From 213f19ca1054eba49f4e71514285fb0ebbf29e0a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 8 Sep 2023 19:48:47 +0200 Subject: [PATCH 1/2] test: show more info on failure in test-cli-syntax-require.js Use spawnSyncAndExit() to show more info when the tes fails. --- test/sequential/test-cli-syntax-require.js | 37 +++++++++------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/test/sequential/test-cli-syntax-require.js b/test/sequential/test-cli-syntax-require.js index 055458ca8542b1..3edcb2d2d09c5f 100644 --- a/test/sequential/test-cli-syntax-require.js +++ b/test/sequential/test-cli-syntax-require.js @@ -1,8 +1,8 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); -const { spawn } = require('child_process'); +const { spawnSyncAndExit } = require('../common/child_process'); const fixtures = require('../common/fixtures'); const node = process.execPath; @@ -17,25 +17,18 @@ const syntaxErrorRE = /^SyntaxError: \b/m; const preloadFile = fixtures.path('no-wrapper.js'); const file = fixtures.path('syntax', 'illegal_if_not_wrapped.js'); const args = [requireFlag, preloadFile, checkFlag, file]; - const cp = spawn(node, args); - - // No stdout should be produced - cp.stdout.on('data', common.mustNotCall('stdout data event')); - - const stderrBuffer = []; - cp.stderr.on('data', (chunk) => stderrBuffer.push(chunk)); - - cp.on('exit', common.mustCall((code, signal) => { - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - - const stderr = Buffer.concat(stderrBuffer).toString('utf-8'); - // stderr should have a syntax error message - assert.match(stderr, syntaxErrorRE); - - // stderr should include the filename - assert(stderr.startsWith(file), `${stderr} starts with ${file}`); - })); - + spawnSyncAndExit(node, args, { + status: 1, + signal: null, + trim: true, + stdout: '', + stderr(output) { + // stderr should have a syntax error message + assert.match(output, syntaxErrorRE); + + // stderr should include the filename + assert(output.startsWith(file), `${output} starts with ${file}`); + } + }); }); }); From 9814b31433cd028c9ddea46f5665ea85a0ed6b39 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 11 Sep 2023 13:39:10 +0200 Subject: [PATCH 2/2] fixup! test: show more info on failure in test-cli-syntax-require.js --- test/sequential/test-cli-syntax-require.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequential/test-cli-syntax-require.js b/test/sequential/test-cli-syntax-require.js index 3edcb2d2d09c5f..5572379f15bc97 100644 --- a/test/sequential/test-cli-syntax-require.js +++ b/test/sequential/test-cli-syntax-require.js @@ -25,7 +25,7 @@ const syntaxErrorRE = /^SyntaxError: \b/m; stderr(output) { // stderr should have a syntax error message assert.match(output, syntaxErrorRE); - + // stderr should include the filename assert(output.startsWith(file), `${output} starts with ${file}`); }