Skip to content

Commit f30b6b2

Browse files
jugglinmikerwaldron
authored andcommitted
Add tests for process exit code
1 parent c2c87c7 commit f30b6b2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

test/test.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const tests = [
3636
'--includesDir', './test/test-includes',
3737
'./test/collateral/test/**/*.js',
3838
],
39+
{ exitCode: 1 },
3940
],
4041
[
4142
[
@@ -47,7 +48,7 @@ const tests = [
4748
'--includesDir', './test-includes',
4849
'collateral/test/**/*.js',
4950
],
50-
{ cwd: 'test' },
51+
{ cwd: 'test', exitCode: 1 },
5152
],
5253
[
5354
[
@@ -115,7 +116,8 @@ const tests = [
115116
'--preprocessor', './test/preprocessor/autofail.js',
116117
'--reporter-keys', 'attrs,result,rawResult',
117118
'./test/collateral-preprocessor/test/autofail.js',
118-
]
119+
],
120+
{ exitCode: 1 },
119121
],
120122
].reduce((accum, a) => {
121123
let b = a.slice();
@@ -143,12 +145,17 @@ function reportRunError(error) {
143145
process.exit(1);
144146
}
145147

146-
function validate({ args, records, options = { prelude: false } }) {
148+
function validate({ args, records, exitCode, options }) {
149+
tap.test(`exit code with args \`${args.join(' ')}\``, assert => {
150+
const expectedExitCode = options && options.exitCode || 0;
151+
assert.equal(exitCode, expectedExitCode, 'exited with correct code');
152+
assert.end();
153+
});
147154

148155
if (options.reporter === 'json') {
149156
records.forEach(record => {
150-
151-
const description = options.prelude ?
157+
const prelude = options && options.prelude;
158+
const description = prelude ?
152159
`${record.attrs.description} with prelude` :
153160
record.attrs.description;
154161

@@ -179,7 +186,7 @@ function validate({ args, records, options = { prelude: false } }) {
179186
'Test fails with appropriate message');
180187
}
181188

182-
if (options.prelude) {
189+
if (prelude) {
183190
assert.ok(record.rawResult.stdout.includes('prelude a!'),
184191
'Has prelude-a content');
185192

test/util/run.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = function run(extraArgs, options) {
3232
resolve({
3333
args,
3434
options,
35+
exitCode: child.exitCode,
3536
records,
3637
});
3738
} catch(e) {

0 commit comments

Comments
 (0)