Skip to content

Commit a55f170

Browse files
committed
test cli per exec with tap
1 parent 120562f commit a55f170

File tree

7 files changed

+290
-158
lines changed

7 files changed

+290
-158
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/node_modules
22
.DS_Store
3+
/.nyc_output
4+
/coverage

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test:
2+
yarn test
3+
4+
test.coverage:
5+
yarn test:cov
6+
7+
.PHONY: test

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
"eslint-plugin-standard": "^4.0.1",
4646
"lint-staged": "^9.4.1",
4747
"prettier": "^1.18.2",
48-
"tap": "^14.6.9",
48+
"tap": "^14.10.5",
4949
"yorkie": "^2.0.0"
50+
},
51+
"resolutions": {
52+
"handlebars": "4.5.0"
5053
}
5154
}

test/cli.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const tap = require('tap')
2+
const { cli } = require('./helper')
3+
4+
tap.test('$ cli', async t => {
5+
const result = await cli([])
6+
t.strictEqual(0, result.code, 'Should succeed')
7+
t.strictEqual(
8+
true,
9+
result.stdout.startsWith('Usage: cli [options] [command]'),
10+
'Should print usage information'
11+
)
12+
t.end()
13+
})
14+
15+
tap.test('$ cli noop', async t => {
16+
const result = await cli(['noop'])
17+
t.strictEqual(0, result.code, 'Should succeed')
18+
t.strictEqual('', result.stdout, 'Should print empty string')
19+
t.end()
20+
})

test/helper.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const path = require('path')
4+
const exec = require('child_process').exec
5+
6+
module.exports.cli = (args, cwd) => {
7+
return new Promise(resolve => {
8+
exec(
9+
`node ${path.resolve(__dirname, '../bin/cli.js')} ${args.join(' ')}`,
10+
{ cwd },
11+
(error, stdout, stderr) => {
12+
resolve({
13+
code: error && error.code ? error.code : 0,
14+
error,
15+
stdout,
16+
stderr
17+
})
18+
}
19+
)
20+
})
21+
}

test/noop.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const tap = require('tap')
2+
3+
tap.test('Test Setup', t => {
4+
t.strictEqual(true, true, 'Tests and assertions should work')
5+
t.end()
6+
})

yarn.lock

+230-157
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)