Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Some unit tests for the cli #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
rtfpessoa merged 15 commits into rtfpessoa:master from whyboris:unit-testing
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions .circleci/config.yml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- ./node_modules
- run: npm run coverage
- run: npm run check-coverage
- run: npm run report

build-latest: &latest-build
docker:
Expand All @@ -31,18 +32,9 @@ jobs:
- ./node_modules
- run: yarn run test
- run: yarn run lint
- run: yarn run coverage-lcov
- run: yarn run codacy

build-node_4:
<<: *common-build
docker:
- image: node:4

build-node_5:
<<: *common-build
docker:
- image: node:5

build-node_6:
<<: *common-build
docker:
Expand All @@ -68,14 +60,18 @@ jobs:
docker:
- image: node:10

build-node_11:
<<: *latest-build
Copy link
Owner

@rtfpessoa rtfpessoa Feb 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Can you change latest-build to common-build in build-node_10 line 59 so we don't push coverage twice?

whyboris reacted with thumbs up emoji
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry have never dealt with this file / config before -- should have been less cavalier when copy-pasting the last command (node 10 -> 11) 😓

docker:
- image: node:11

workflows:
version: 2
build:
jobs:
- build-node_4
- build-node_5
- build-node_6
- build-node_7
- build-node_8
- build-node_9
- build-node_10
- build-node_11
3 changes: 2 additions & 1 deletion .gitignore
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ node_modules/
npm-debug.log
yarn-error.log

# Istanbul
# NYC
coverage/
.nyc_output/

# Bower
bower_components/
16 changes: 10 additions & 6 deletions package.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@
"url": "https://www.github.com/rtfpessoa/diff2html-cli/issues"
},
"engines": {
"node": ">=4"
"node": ">=6"
},
"preferGlobal": true,
"scripts": {
"lint": "eslint .",
"style": "yarn run lint",
"coverage": "istanbul cover _mocha -- -u exports -R spec ./test/**/*",
"check-coverage": "istanbul check-coverage --statements 50 --functions 40 --branches 0 --lines 50 ./coverage/coverage.json",
"test": "yarn run coverage",
"coverage": "nyc mocha",
"coverage-html": "nyc report --reporter=html && open ./coverage/index.html",
"check-coverage": "nyc check-coverage --statements 40 --functions 40 --branches 0 --lines 40",
"report": "nyc report",
"coverage-lcov": "nyc report --reporter=lcov",
"codacy": "cat ./coverage/lcov.info | codacy-coverage",
"preversion": "yarn run test",
"postversion": "git push && git push --tags"
Expand All @@ -59,11 +62,12 @@
},
"devDependencies": {
"codacy-coverage": "^3.0.0",
"eslint": "^4.19.1",
"eslint": "^5.13.0",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"istanbul": "^0.4.5",
"mocha": "^5.2.0"
"nyc": "^13.2.0",
"mocha": "^5.2.0",
"sinon": "^7.2.3"
},
"license": "MIT",
"files": [
Expand Down
52 changes: 52 additions & 0 deletions test/cli-tests.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var assert = require('assert');

var sinon = require('sinon');

var Cli = require('../src/cli.js').Diff2HtmlInterface;
var http = require('../src/http-utils.js').HttpUtils;
var Utils = require('../src/utils.js').Utils;

describe('Cli', function() {
describe('getInput', function() {
it('should readFile when inputType is `file`', function() {
var spy = sinon.stub(Utils, 'readFile');
Cli.getInput('file', ['lol', 'foo'], 'ignore', 'callback');
assert(spy.calledOnce);
assert(spy.calledWith('lol', 'callback'));
spy.restore();
});

it('should readStdin when inputType is `stdin`', function() {
var spy = sinon.stub(Utils, 'readStdin');
Cli.getInput('stdin', ['lol'], 'ignore', 'callback');
assert(spy.calledOnce);
assert(spy.calledWith('callback'));
spy.restore();
});

it('should _runGitDiff by default', function() {
var spy = sinon.stub(Cli, '_runGitDiff');
Cli.getInput('abc', ['lol', 'foo'], 'ignore', 'callback');
assert(spy.calledOnce);
assert(spy.calledWith(['lol', 'foo'], 'ignore', 'callback'));
});
});

describe('preview', function() {
it('should call `utils.writeFile`', function() {
var spy = sinon.stub(Utils, 'writeFile');
Cli.preview('a', 'b');
assert(spy.calledOnce);
spy.restore();
});
});

describe('postToDiffy', function() {
it('should call `http.post`', function() {
var spy = sinon.stub(http, 'post');
Cli.postToDiffy('a', 'b', 'callback');
assert(spy.calledOnce);
assert(spy.calledWith('http://diffy.org/api/new', { udiff: 'a' }));
});
});
});
Loading

AltStyle によって変換されたページ (->オリジナル) /