Skip to content

Commit c70c74a

Browse files
joyeecheungruyadorno
authored andcommitted
test: show more info on failure in test-cli-syntax-require.js
Use spawnSyncAndExit() to show more info when the tes fails. PR-URL: #49561 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Ruy Adorno <ruyadorno@google.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
1 parent 728ebf6 commit c70c74a

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed
+15-22
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
const common = require('../common');
3+
require('../common');
44
const assert = require('assert');
5-
const { spawn } = require('child_process');
5+
const { spawnSyncAndExit } = require('../common/child_process');
66
const fixtures = require('../common/fixtures');
77

88
const node = process.execPath;
@@ -17,25 +17,18 @@ const syntaxErrorRE = /^SyntaxError: \b/m;
1717
const preloadFile = fixtures.path('no-wrapper.js');
1818
const file = fixtures.path('syntax', 'illegal_if_not_wrapped.js');
1919
const args = [requireFlag, preloadFile, checkFlag, file];
20-
const cp = spawn(node, args);
21-
22-
// No stdout should be produced
23-
cp.stdout.on('data', common.mustNotCall('stdout data event'));
24-
25-
const stderrBuffer = [];
26-
cp.stderr.on('data', (chunk) => stderrBuffer.push(chunk));
27-
28-
cp.on('exit', common.mustCall((code, signal) => {
29-
assert.strictEqual(code, 1);
30-
assert.strictEqual(signal, null);
31-
32-
const stderr = Buffer.concat(stderrBuffer).toString('utf-8');
33-
// stderr should have a syntax error message
34-
assert.match(stderr, syntaxErrorRE);
35-
36-
// stderr should include the filename
37-
assert(stderr.startsWith(file), `${stderr} starts with ${file}`);
38-
}));
39-
20+
spawnSyncAndExit(node, args, {
21+
status: 1,
22+
signal: null,
23+
trim: true,
24+
stdout: '',
25+
stderr(output) {
26+
// stderr should have a syntax error message
27+
assert.match(output, syntaxErrorRE);
28+
29+
// stderr should include the filename
30+
assert(output.startsWith(file), `${output} starts with ${file}`);
31+
}
32+
});
4033
});
4134
});

0 commit comments

Comments
 (0)