Skip to content

Commit 70434e2

Browse files
authored
Merge pull request #45 from whyboris/unit-testing
Some unit tests for the cli
2 parents a8c4a59 + 79b581a commit 70434e2

File tree

5 files changed

+1122
-450
lines changed

5 files changed

+1122
-450
lines changed

.circleci/config.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- ./node_modules
1616
- run: npm run coverage
1717
- run: npm run check-coverage
18+
- run: npm run report
1819

1920
build-latest: &latest-build
2021
docker:
@@ -31,18 +32,9 @@ jobs:
3132
- ./node_modules
3233
- run: yarn run test
3334
- run: yarn run lint
35+
- run: yarn run coverage-lcov
3436
- run: yarn run codacy
3537

36-
build-node_4:
37-
<<: *common-build
38-
docker:
39-
- image: node:4
40-
41-
build-node_5:
42-
<<: *common-build
43-
docker:
44-
- image: node:5
45-
4638
build-node_6:
4739
<<: *common-build
4840
docker:
@@ -64,18 +56,22 @@ jobs:
6456
- image: node:9
6557

6658
build-node_10:
67-
<<: *latest-build
59+
<<: *common-build
6860
docker:
6961
- image: node:10
7062

63+
build-node_11:
64+
<<: *latest-build
65+
docker:
66+
- image: node:11
67+
7168
workflows:
7269
version: 2
7370
build:
7471
jobs:
75-
- build-node_4
76-
- build-node_5
7772
- build-node_6
7873
- build-node_7
7974
- build-node_8
8075
- build-node_9
8176
- build-node_10
77+
- build-node_11

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ node_modules/
2020
npm-debug.log
2121
yarn-error.log
2222

23-
# Istanbul
23+
# NYC
2424
coverage/
25+
.nyc_output/
2526

2627
# Bower
2728
bower_components/

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@
3232
"url": "https://www.github.com/rtfpessoa/diff2html-cli/issues"
3333
},
3434
"engines": {
35-
"node": ">=4"
35+
"node": ">=6"
3636
},
3737
"preferGlobal": true,
3838
"scripts": {
3939
"lint": "eslint .",
4040
"style": "yarn run lint",
41-
"coverage": "istanbul cover _mocha -- -u exports -R spec ./test/**/*",
42-
"check-coverage": "istanbul check-coverage --statements 50 --functions 40 --branches 0 --lines 50 ./coverage/coverage.json",
4341
"test": "yarn run coverage",
42+
"coverage": "nyc mocha",
43+
"coverage-html": "nyc report --reporter=html && open ./coverage/index.html",
44+
"check-coverage": "nyc check-coverage --statements 40 --functions 40 --branches 0 --lines 40",
45+
"report": "nyc report",
46+
"coverage-lcov": "nyc report --reporter=lcov",
4447
"codacy": "cat ./coverage/lcov.info | codacy-coverage",
4548
"preversion": "yarn run test",
4649
"postversion": "git push && git push --tags"
@@ -59,11 +62,12 @@
5962
},
6063
"devDependencies": {
6164
"codacy-coverage": "^3.0.0",
62-
"eslint": "^4.19.1",
65+
"eslint": "^5.13.0",
6366
"eslint-plugin-promise": "^3.8.0",
6467
"eslint-plugin-standard": "^3.1.0",
65-
"istanbul": "^0.4.5",
66-
"mocha": "^5.2.0"
68+
"nyc": "^13.2.0",
69+
"mocha": "^5.2.0",
70+
"sinon": "^7.2.3"
6771
},
6872
"license": "MIT",
6973
"files": [

test/cli-tests.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var assert = require('assert');
2+
3+
var sinon = require('sinon');
4+
5+
var Cli = require('../src/cli.js').Diff2HtmlInterface;
6+
var http = require('../src/http-utils.js').HttpUtils;
7+
var Utils = require('../src/utils.js').Utils;
8+
9+
describe('Cli', function() {
10+
describe('getInput', function() {
11+
it('should readFile when inputType is `file`', function() {
12+
var spy = sinon.stub(Utils, 'readFile');
13+
Cli.getInput('file', ['lol', 'foo'], 'ignore', 'callback');
14+
assert(spy.calledOnce);
15+
assert(spy.calledWith('lol', 'callback'));
16+
spy.restore();
17+
});
18+
19+
it('should readStdin when inputType is `stdin`', function() {
20+
var spy = sinon.stub(Utils, 'readStdin');
21+
Cli.getInput('stdin', ['lol'], 'ignore', 'callback');
22+
assert(spy.calledOnce);
23+
assert(spy.calledWith('callback'));
24+
spy.restore();
25+
});
26+
27+
it('should _runGitDiff by default', function() {
28+
var spy = sinon.stub(Cli, '_runGitDiff');
29+
Cli.getInput('abc', ['lol', 'foo'], 'ignore', 'callback');
30+
assert(spy.calledOnce);
31+
assert(spy.calledWith(['lol', 'foo'], 'ignore', 'callback'));
32+
});
33+
});
34+
35+
describe('preview', function() {
36+
it('should call `utils.writeFile`', function() {
37+
var spy = sinon.stub(Utils, 'writeFile');
38+
Cli.preview('a', 'b');
39+
assert(spy.calledOnce);
40+
spy.restore();
41+
});
42+
});
43+
44+
describe('postToDiffy', function() {
45+
it('should call `http.post`', function() {
46+
var spy = sinon.stub(http, 'post');
47+
Cli.postToDiffy('a', 'b', 'callback');
48+
assert(spy.calledOnce);
49+
assert(spy.calledWith('http://diffy.org/api/new', { udiff: 'a' }));
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)