Skip to content

Commit 396e17c

Browse files
committed
test: use spawnSyncAndExitWithoutError()
Use `spawnSyncAndExitWithoutError()` in `test/parallel/test-macos-app-sandbox.js`. Refs: #54802 (comment)
1 parent dc5d0f9 commit 396e17c

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

test/parallel/test-macos-app-sandbox.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ if (process.config.variables.node_builtin_modules_path)
77

88
const fixtures = require('../common/fixtures');
99
const tmpdir = require('../common/tmpdir');
10-
const assert = require('assert');
11-
const child_process = require('child_process');
1210
const path = require('path');
1311
const fs = require('fs');
1412
const os = require('os');
13+
const {
14+
spawnSyncAndExit,
15+
spawnSyncAndExitWithoutError
16+
} = require('../common/child_process');
1517

1618
const nodeBinary = process.execPath;
1719

@@ -42,30 +44,29 @@ fs.copyFileSync(
4244
nodeBinary,
4345
appExecutablePath);
4446

45-
4647
// Sign the app bundle with sandbox entitlements:
47-
assert.strictEqual(
48-
child_process.spawnSync('/usr/bin/codesign', [
49-
'--entitlements', fixtures.path(
50-
'macos-app-sandbox', 'node_sandboxed.entitlements'),
51-
'--force', '-s', '-',
52-
appBundlePath,
53-
]).status,
54-
0);
48+
spawnSyncAndExitWithoutError('codesign', [
49+
'--entitlements',
50+
fixtures.path('macos-app-sandbox', 'node_sandboxed.entitlements'),
51+
'--force',
52+
'-s',
53+
'-',
54+
appBundlePath,
55+
]);
5556

5657
// Sandboxed app shouldn't be able to read the home dir
57-
assert.notStrictEqual(
58-
child_process.spawnSync(appExecutablePath, [
59-
'-e', 'fs.readdirSync(process.argv[1])', os.homedir(),
60-
]).status,
61-
0);
58+
spawnSyncAndExit(
59+
appExecutablePath,
60+
['-e', 'fs.readdirSync(process.argv[1])', os.homedir()],
61+
{
62+
status: 1,
63+
signal: null,
64+
},
65+
);
6266

6367
if (process.stdin.isTTY) {
6468
// Run the sandboxed node instance with inherited tty stdin
65-
const spawnResult = child_process.spawnSync(
66-
appExecutablePath, ['-e', ''],
67-
{ stdio: 'inherit' }
68-
);
69-
70-
assert.strictEqual(spawnResult.signal, null);
69+
spawnSyncAndExitWithoutError(appExecutablePath, ['-e', ''], {
70+
stdio: 'inherit',
71+
});
7172
}

0 commit comments

Comments
 (0)