Skip to content

Commit 933db79

Browse files
test: assert for exit code (#137)
* chore: bump cli-prompts-test * test: assert for exit code
1 parent fb70857 commit 933db79

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

e2e/commands/generate.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ test('generate _sidebar.md', t => {
2626
// Check for existence
2727
t.true(fs.existsSync(path.join(docsPath, '_sidebar.md')))
2828

29-
const {stderr} = run(['generate', 'docs'], {cwd: genPath})
29+
const {exitCode, stderr} = run(['generate', 'docs'], {
30+
cwd: genPath,
31+
reject: false
32+
})
33+
t.is(exitCode, 1)
3034
t.is(stderr, 'The sidebar file \'_sidebar.md\' already exists.')
3135
})

e2e/commands/init.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@ test.after('cleanup', () => {
2222
})
2323

2424
test('generates docs directory', t => {
25-
run(['init', 'docs'], {cwd: genPath})
25+
const {exitCode} = run(['init', 'docs'], {cwd: genPath})
26+
27+
// Assert for exit code
28+
t.is(exitCode, 0)
29+
2630
// Check for existence
2731
t.true(fs.existsSync(path.join(docsPath, 'README.md')))
2832
t.true(fs.existsSync(path.join(docsPath, 'index.html')))
2933
})
3034

3135
test('force generates docs directory with --local flag', async t => {
32-
await runPromptWithAnswers(['init', 'docs', '--local'], ['y', ENTER], genPath)
36+
const {exitCode} = await runPromptWithAnswers(
37+
['init', 'docs', '--local'],
38+
['y', ENTER],
39+
genPath
40+
)
41+
t.is(exitCode, 0)
3342
t.true(fs.existsSync(path.join(docsPath, 'vendor')))
3443
})

lib/commands/generate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = function (path = '', sidebar) {
2222
}
2323

2424
console.error(chalk.red(`The sidebar file '${sidebar}' already exists.`))
25+
process.exitCode = 1
2526
return false
2627
}
2728
}

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
"devDependencies": {
7474
"ava": "^3.13.0",
75-
"cli-prompts-test": "^0.2.0",
75+
"cli-prompts-test": "^0.3.0",
7676
"cors": "^2.8.1",
7777
"eslint": "^6.8.0",
7878
"eslint-config-xo-space": "^0.22.0",

0 commit comments

Comments
 (0)