Skip to content

Commit 31657f7

Browse files
joyeecheungnodejs-github-bot
authored andcommitted
test: use spawnSyncAndExitWithoutError in test/common/sea.js
To display more information when the command fails. PR-URL: #49543 Refs: nodejs/reliability#658 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent dca4d84 commit 31657f7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

test/common/sea.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const common = require('../common');
44
const fixtures = require('../common/fixtures');
55

66
const { readFileSync } = require('fs');
7-
const { execFileSync } = require('child_process');
7+
const {
8+
spawnSyncAndExitWithoutError,
9+
} = require('../common/child_process');
810

911
function skipIfSingleExecutableIsNotSupported() {
1012
if (!process.config.variables.single_executable_application)
@@ -45,38 +47,39 @@ function skipIfSingleExecutableIsNotSupported() {
4547

4648
function injectAndCodeSign(targetExecutable, resource) {
4749
const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js');
48-
execFileSync(process.execPath, [
50+
spawnSyncAndExitWithoutError(process.execPath, [
4951
postjectFile,
5052
targetExecutable,
5153
'NODE_SEA_BLOB',
5254
resource,
5355
'--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
5456
...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [],
55-
]);
57+
], {});
5658

5759
if (process.platform === 'darwin') {
58-
execFileSync('codesign', [ '--sign', '-', targetExecutable ]);
59-
execFileSync('codesign', [ '--verify', targetExecutable ]);
60+
spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ], {});
61+
spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ], {});
6062
} else if (process.platform === 'win32') {
6163
let signtoolFound = false;
6264
try {
63-
execFileSync('where', [ 'signtool' ]);
65+
spawnSyncAndExitWithoutError('where', [ 'signtool' ], {});
6466
signtoolFound = true;
6567
} catch (err) {
6668
console.log(err.message);
6769
}
6870
if (signtoolFound) {
6971
let certificatesFound = false;
72+
let stderr;
7073
try {
71-
execFileSync('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ]);
74+
({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], {}));
7275
certificatesFound = true;
7376
} catch (err) {
74-
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(err)) {
77+
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(stderr)) {
7578
throw err;
7679
}
7780
}
7881
if (certificatesFound) {
79-
execFileSync('signtool', 'verify', '/pa', 'SHA256', targetExecutable);
82+
spawnSyncAndExitWithoutError('signtool', 'verify', '/pa', 'SHA256', targetExecutable, {});
8083
}
8184
}
8285
}

0 commit comments

Comments
 (0)