Skip to content

Commit 8358796

Browse files
author
whyboris
committed
unit test cli getInput method
1 parent 9d11ace commit 8358796

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"extend": "^3.0.1",
5656
"open": "^0.0.5",
5757
"request": "^2.87.0",
58+
"sinon": "^7.2.3",
5859
"yargs": "^11.0.0"
5960
},
6061
"devDependencies": {

test/cli-tests.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var assert = require('assert');
2+
3+
var sinon = require('sinon')
4+
5+
var Cli = require('../src/cli.js').Diff2HtmlInterface;
6+
var Utils = require('../src/utils.js').Utils;
7+
8+
describe('Cli', function() {
9+
describe('getInput', function() {
10+
it('should readFile when inputType is `file`', function() {
11+
let spy = sinon.stub(Utils, 'readFile');
12+
Cli.getInput('file', ['lol', 'foo'], 'callback');
13+
assert(spy.calledOnce);
14+
assert(spy.calledWith('lol', 'callback'));
15+
spy.restore()
16+
});
17+
18+
it('should readStdin when inputType is `stdin`', function() {
19+
let spy = sinon.stub(Utils, 'readStdin');
20+
Cli.getInput('stdin', ['lol'], 'callback');
21+
assert(spy.calledOnce);
22+
assert(spy.calledWith('callback'));
23+
});
24+
25+
it('should _runGitDiff by default', function() {
26+
let spy = sinon.stub(Cli, '_runGitDiff');
27+
Cli.getInput('abc', ['lol'], 'callback');
28+
assert(spy.calledOnce);
29+
assert(spy.calledWith(['lol'], 'callback'));
30+
});
31+
});
32+
});

yarn.lock

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22
# yarn lockfile v1
33

44

5+
"@sinonjs/commons@^1.0.2", "@sinonjs/commons@^1.3.0":
6+
version "1.3.0"
7+
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.3.0.tgz#50a2754016b6f30a994ceda6d9a0a8c36adda849"
8+
integrity sha512-j4ZwhaHmwsCb4DlDOIWnI5YyKDNMoNThsmwEpfHx6a1EpsGZ9qYLxP++LMlmBRjtGptGHFsGItJ768snllFWpA==
9+
dependencies:
10+
type-detect "4.0.8"
11+
12+
"@sinonjs/formatio@^3.1.0":
13+
version "3.1.0"
14+
resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-3.1.0.tgz#6ac9d1eb1821984d84c4996726e45d1646d8cce5"
15+
integrity sha512-ZAR2bPHOl4Xg6eklUGpsdiIJ4+J1SNag1DHHrG/73Uz/nVwXqjgUtRPLoS+aVyieN9cSbc0E4LsU984tWcDyNg==
16+
dependencies:
17+
"@sinonjs/samsam" "^2 || ^3"
18+
19+
"@sinonjs/samsam@^2 || ^3", "@sinonjs/samsam@^3.0.2":
20+
version "3.1.0"
21+
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-3.1.0.tgz#38146f7be732de96f9f599d7247d71e349bf4bdb"
22+
integrity sha512-IXio+GWY+Q8XUjHUOgK7wx8fpvr7IFffgyXb1bnJFfX3001KmHt35Zq4tp7MXZyjJPCLPuadesDYNk41LYtVjw==
23+
dependencies:
24+
"@sinonjs/commons" "^1.0.2"
25+
array-from "^2.1.1"
26+
lodash.get "^4.4.2"
27+
528
abbrev@1, abbrev@1.0.x:
629
version "1.0.9"
730
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
@@ -82,6 +105,11 @@ argparse@^1.0.7:
82105
dependencies:
83106
sprintf-js "~1.0.2"
84107

108+
array-from@^2.1.1:
109+
version "2.1.1"
110+
resolved "https://registry.yarnpkg.com/array-from/-/array-from-2.1.1.tgz#cfe9d8c26628b9dc5aecc62a9f5d8f1f352c1195"
111+
integrity sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=
112+
85113
array-union@^1.0.1:
86114
version "1.0.2"
87115
resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39"
@@ -833,6 +861,11 @@ is-typedarray@~1.0.0:
833861
version "1.0.0"
834862
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
835863

864+
isarray@0.0.1:
865+
version "0.0.1"
866+
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
867+
integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=
868+
836869
isarray@~1.0.0:
837870
version "1.0.0"
838871
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@@ -948,6 +981,11 @@ jsprim@^1.2.2:
948981
json-schema "0.2.3"
949982
verror "1.3.6"
950983

984+
just-extend@^4.0.2:
985+
version "4.0.2"
986+
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-4.0.2.tgz#f3f47f7dfca0f989c55410a7ebc8854b07108afc"
987+
integrity sha512-FrLwOgm+iXrPV+5zDU6Jqu4gCRXbWEQg2O3SKONsWE4w7AXFRkryS53bpWdaL9cNol+AmR3AEYz6kn+o0fCPnw==
988+
951989
kind-of@^3.0.2:
952990
version "3.0.4"
953991
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.0.4.tgz#7b8ecf18a4e17f8269d73b501c9f232c96887a74"
@@ -982,6 +1020,11 @@ locate-path@^2.0.0:
9821020
p-locate "^2.0.0"
9831021
path-exists "^3.0.0"
9841022

1023+
lodash.get@^4.4.2:
1024+
version "4.4.2"
1025+
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
1026+
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=
1027+
9851028
lodash@^4.13.1, lodash@^4.17.10:
9861029
version "4.17.10"
9871030
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
@@ -998,6 +1041,16 @@ log-driver@^1.x:
9981041
version "1.2.5"
9991042
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.5.tgz#7ae4ec257302fd790d557cb10c97100d857b0056"
10001043

1044+
lolex@^2.3.2:
1045+
version "2.7.5"
1046+
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.5.tgz#113001d56bfc7e02d56e36291cc5c413d1aa0733"
1047+
integrity sha512-l9x0+1offnKKIzYVjyXU2SiwhXDLekRzKyhnbyldPHvC7BvLPVpdNUNR2KeMAiCN2D/kLNttZgQD5WjSxuBx3Q==
1048+
1049+
lolex@^3.0.0:
1050+
version "3.0.0"
1051+
resolved "https://registry.yarnpkg.com/lolex/-/lolex-3.0.0.tgz#f04ee1a8aa13f60f1abd7b0e8f4213ec72ec193e"
1052+
integrity sha512-hcnW80h3j2lbUfFdMArd5UPA/vxZJ+G8vobd+wg3nVEQA0EigStbYcrG030FJxL6xiDDPEkoMatV9xIh5OecQQ==
1053+
10011054
longest@^1.0.1:
10021055
version "1.0.1"
10031056
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
@@ -1093,6 +1146,17 @@ natural-compare@^1.4.0:
10931146
version "1.4.0"
10941147
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
10951148

1149+
nise@^1.4.8:
1150+
version "1.4.8"
1151+
resolved "https://registry.yarnpkg.com/nise/-/nise-1.4.8.tgz#ce91c31e86cf9b2c4cac49d7fcd7f56779bfd6b0"
1152+
integrity sha512-kGASVhuL4tlAV0tvA34yJYZIVihrUt/5bDwpp4tTluigxUr2bBlJeDXmivb6NuEdFkqvdv/Ybb9dm16PSKUhtw==
1153+
dependencies:
1154+
"@sinonjs/formatio" "^3.1.0"
1155+
just-extend "^4.0.2"
1156+
lolex "^2.3.2"
1157+
path-to-regexp "^1.7.0"
1158+
text-encoding "^0.6.4"
1159+
10961160
nopt@1.0.10:
10971161
version "1.0.10"
10981162
resolved "https://registry.yarnpkg.com/nopt/-/nopt-1.0.10.tgz#6ddd21bd2a31417b92727dd585f8a6f37608ebee"
@@ -1199,6 +1263,13 @@ path-key@^2.0.0:
11991263
version "2.0.1"
12001264
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
12011265

1266+
path-to-regexp@^1.7.0:
1267+
version "1.7.0"
1268+
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
1269+
integrity sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=
1270+
dependencies:
1271+
isarray "0.0.1"
1272+
12021273
performance-now@^2.1.0:
12031274
version "2.1.0"
12041275
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
@@ -1401,6 +1472,19 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
14011472
version "3.0.2"
14021473
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
14031474

1475+
sinon@^7.2.3:
1476+
version "7.2.3"
1477+
resolved "https://registry.yarnpkg.com/sinon/-/sinon-7.2.3.tgz#f8bfd956df32ddf592f8c102fd46982366412d8e"
1478+
integrity sha512-i6j7sqcLEqTYqUcMV327waI745VASvYuSuQMCjbAwlpAeuCgKZ3LtrjDxAbu+GjNQR0FEDpywtwGCIh8GicNyg==
1479+
dependencies:
1480+
"@sinonjs/commons" "^1.3.0"
1481+
"@sinonjs/formatio" "^3.1.0"
1482+
"@sinonjs/samsam" "^3.0.2"
1483+
diff "^3.5.0"
1484+
lolex "^3.0.0"
1485+
nise "^1.4.8"
1486+
supports-color "^5.5.0"
1487+
14041488
slice-ansi@1.0.0:
14051489
version "1.0.0"
14061490
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-1.0.0.tgz#044f1a49d8842ff307aad6b505ed178bd950134d"
@@ -1507,6 +1591,13 @@ supports-color@^4.0.0:
15071591
dependencies:
15081592
has-flag "^2.0.0"
15091593

1594+
supports-color@^5.5.0:
1595+
version "5.5.0"
1596+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
1597+
integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==
1598+
dependencies:
1599+
has-flag "^3.0.0"
1600+
15101601
sync-exec@~0.6.x:
15111602
version "0.6.2"
15121603
resolved "https://registry.yarnpkg.com/sync-exec/-/sync-exec-0.6.2.tgz#717d22cc53f0ce1def5594362f3a89a2ebb91105"
@@ -1522,6 +1613,11 @@ table@4.0.2:
15221613
slice-ansi "1.0.0"
15231614
string-width "^2.1.1"
15241615

1616+
text-encoding@^0.6.4:
1617+
version "0.6.4"
1618+
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
1619+
integrity sha1-45mpgiV6J22uQou5KEXLcb3CbRk=
1620+
15251621
text-table@~0.2.0:
15261622
version "0.2.0"
15271623
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
@@ -1575,6 +1671,11 @@ type-check@~0.3.2:
15751671
dependencies:
15761672
prelude-ls "~1.1.2"
15771673

1674+
type-detect@4.0.8:
1675+
version "4.0.8"
1676+
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
1677+
integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==
1678+
15781679
typedarray@^0.0.6:
15791680
version "0.0.6"
15801681
resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

0 commit comments

Comments
 (0)