From 586b2092115620bf484fed79213890b8bb94cae9 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 7 Sep 2023 22:02:28 +0200 Subject: [PATCH 1/2] test: use spawnSyncAndExitWithoutError in test/common/sea.js To display more information when the command fails. --- test/common/sea.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/common/sea.js b/test/common/sea.js index bb337f176f2cc2..cc1890a5464012 100644 --- a/test/common/sea.js +++ b/test/common/sea.js @@ -4,7 +4,9 @@ const common = require('../common'); const fixtures = require('../common/fixtures'); const { readFileSync } = require('fs'); -const { execFileSync } = require('child_process'); +const { + spawnSyncAndExitWithoutError, +} = require('../common/child_process'); function skipIfSingleExecutableIsNotSupported() { if (!process.config.variables.single_executable_application) @@ -45,38 +47,39 @@ function skipIfSingleExecutableIsNotSupported() { function injectAndCodeSign(targetExecutable, resource) { const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js'); - execFileSync(process.execPath, [ + spawnSyncAndExitWithoutError(process.execPath, [ postjectFile, targetExecutable, 'NODE_SEA_BLOB', resource, '--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2', ...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [], - ]); + ], {}); if (process.platform === 'darwin') { - execFileSync('codesign', [ '--sign', '-', targetExecutable ]); - execFileSync('codesign', [ '--verify', targetExecutable ]); + spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ], {}); + spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ], {}); } else if (process.platform === 'win32') { let signtoolFound = false; try { - execFileSync('where', [ 'signtool' ]); + spawnSyncAndExitWithoutError('where', [ 'signtool' ], {}); signtoolFound = true; } catch (err) { console.log(err.message); } if (signtoolFound) { let certificatesFound = false; + let stderr; try { - execFileSync('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ]); + ({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], {})); certificatesFound = true; } catch (err) { - if (!/SignTool Error: No certificates were found that met all the given criteria/.test(err)) { + if (!/SignTool Error: No certificates were found that met all the given criteria/.test(stderr)) { throw err; } } if (certificatesFound) { - execFileSync('signtool', 'verify', '/pa', 'SHA256', targetExecutable); + spawnSyncAndExitWithoutError('signtool', 'verify', '/pa', 'SHA256', targetExecutable, {}); } } } From 6b8ecfb0169484702fe3c5b223b5db3860b4fa2c Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 7 Sep 2023 22:03:03 +0200 Subject: [PATCH 2/2] test: use spawnSyncAndExitWithoutError in sea tests To display more information when the command fails. --- ...ble-application-snapshot-and-code-cache.js | 21 ++++++---- ...-single-executable-application-snapshot.js | 41 ++++++++++++------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/test/sequential/test-single-executable-application-snapshot-and-code-cache.js b/test/sequential/test-single-executable-application-snapshot-and-code-cache.js index 66012e38a4faa6..6d86d6a79d8d68 100644 --- a/test/sequential/test-single-executable-application-snapshot-and-code-cache.js +++ b/test/sequential/test-single-executable-application-snapshot-and-code-cache.js @@ -13,7 +13,9 @@ skipIfSingleExecutableIsNotSupported(); const tmpdir = require('../common/tmpdir'); const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSync } = require('child_process'); +const { + spawnSyncAndExitWithoutError +} = require('../common/child_process'); const { join } = require('path'); const assert = require('assert'); @@ -43,21 +45,24 @@ const outputFile = join(tmpdir.path, process.platform === 'win32' ? 'sea.exe' : } `); - let child = spawnSync( + spawnSyncAndExitWithoutError( process.execPath, ['--experimental-sea-config', 'sea-config.json'], { cwd: tmpdir.path - }); - assert.match( - child.stderr.toString(), - /"useCodeCache" is redundant when "useSnapshot" is true/); + }, + { + stderr: /"useCodeCache" is redundant when "useSnapshot" is true/ + } + ); assert(existsSync(seaPrepBlob)); copyFileSync(process.execPath, outputFile); injectAndCodeSign(outputFile, seaPrepBlob); - child = spawnSync(outputFile); - assert.strictEqual(child.stdout.toString().trim(), 'Hello from snapshot'); + spawnSyncAndExitWithoutError(outputFile, { + stdout: 'Hello from snapshot', + trim: true, + }); } diff --git a/test/sequential/test-single-executable-application-snapshot.js b/test/sequential/test-single-executable-application-snapshot.js index 51b09cea662adf..5c2d8c36fdd38f 100644 --- a/test/sequential/test-single-executable-application-snapshot.js +++ b/test/sequential/test-single-executable-application-snapshot.js @@ -13,7 +13,10 @@ skipIfSingleExecutableIsNotSupported(); const tmpdir = require('../common/tmpdir'); const { copyFileSync, writeFileSync, existsSync } = require('fs'); -const { spawnSync } = require('child_process'); +const { + spawnSyncAndExit, + spawnSyncAndExitWithoutError +} = require('../common/child_process'); const assert = require('assert'); const configFile = tmpdir.resolve('sea-config.json'); @@ -32,16 +35,17 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se } `); - const child = spawnSync( + spawnSyncAndExit( process.execPath, ['--experimental-sea-config', 'sea-config.json'], { cwd: tmpdir.path + }, + { + status: 1, + signal: null, + stderr: /snapshot\.js does not invoke v8\.startupSnapshot\.setDeserializeMainFunction\(\)/ }); - - assert.match( - child.stderr.toString(), - /snapshot\.js does not invoke v8\.startupSnapshot\.setDeserializeMainFunction\(\)/); } { @@ -65,24 +69,31 @@ const outputFile = tmpdir.resolve(process.platform === 'win32' ? 'sea.exe' : 'se } `); - let child = spawnSync( + spawnSyncAndExitWithoutError( process.execPath, ['--experimental-sea-config', 'sea-config.json'], { cwd: tmpdir.path + }, + { + stderr: /Single executable application is an experimental feature/ }); - assert.match( - child.stderr.toString(), - /Single executable application is an experimental feature/); assert(existsSync(seaPrepBlob)); copyFileSync(process.execPath, outputFile); injectAndCodeSign(outputFile, seaPrepBlob); - child = spawnSync(outputFile); - assert.strictEqual(child.stdout.toString().trim(), 'Hello from snapshot'); - assert.doesNotMatch( - child.stderr.toString(), - /Single executable application is an experimental feature/); + spawnSyncAndExitWithoutError( + outputFile, + { + trim: true, + stdout: 'Hello from snapshot', + stderr(output) { + assert.doesNotMatch( + output, + /Single executable application is an experimental feature/); + } + } + ); }