Skip to content

Commit

Permalink
Add tests for process exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed May 25, 2021
1 parent c2c87c7 commit f30b6b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const tests = [
'--includesDir', './test/test-includes',
'./test/collateral/test/**/*.js',
],
{ exitCode: 1 },
],
[
[
Expand All @@ -47,7 +48,7 @@ const tests = [
'--includesDir', './test-includes',
'collateral/test/**/*.js',
],
{ cwd: 'test' },
{ cwd: 'test', exitCode: 1 },
],
[
[
Expand Down Expand Up @@ -115,7 +116,8 @@ const tests = [
'--preprocessor', './test/preprocessor/autofail.js',
'--reporter-keys', 'attrs,result,rawResult',
'./test/collateral-preprocessor/test/autofail.js',
]
],
{ exitCode: 1 },
],
].reduce((accum, a) => {
let b = a.slice();
Expand Down Expand Up @@ -143,12 +145,17 @@ function reportRunError(error) {
process.exit(1);
}

function validate({ args, records, options = { prelude: false } }) {
function validate({ args, records, exitCode, options }) {
tap.test(`exit code with args \`${args.join(' ')}\``, assert => {
const expectedExitCode = options && options.exitCode || 0;
assert.equal(exitCode, expectedExitCode, 'exited with correct code');
assert.end();
});

if (options.reporter === 'json') {
records.forEach(record => {

const description = options.prelude ?
const prelude = options && options.prelude;
const description = prelude ?
`${record.attrs.description} with prelude` :
record.attrs.description;

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

if (options.prelude) {
if (prelude) {
assert.ok(record.rawResult.stdout.includes('prelude a!'),
'Has prelude-a content');

Expand Down
1 change: 1 addition & 0 deletions test/util/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = function run(extraArgs, options) {
resolve({
args,
options,
exitCode: child.exitCode,
records,
});
} catch(e) {
Expand Down

0 comments on commit f30b6b2

Please sign in to comment.