Skip to content

Commit b0e2f9a

Browse files
cjihrigMylesBorins
authored andcommitted
test: add common.rootDir
A few of the child process tests can be simplified by computing the OS specific root directory in common and then accessing that value. PR-URL: #7685 Reviewed-By: Roman Reiss <[email protected]>
1 parent e8be413 commit b0e2f9a

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

test/common.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ exports.isSunOS = process.platform === 'sunos';
2727
exports.isFreeBSD = process.platform === 'freebsd';
2828

2929
exports.enoughTestMem = os.totalmem() > 0x20000000; /* 512MB */
30+
exports.rootDir = exports.isWindows ? 'c:\\' : '/';
3031

3132
function rimrafSync(p) {
3233
try {

test/parallel/test-child-process-cwd.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ function testCwd(options, forCode, forData) {
3636
}
3737

3838
// Assume these exist, and 'pwd' gives us the right directory back
39+
testCwd({cwd: common.rootDir}, 0, common.rootDir);
3940
if (common.isWindows) {
4041
testCwd({cwd: process.env.windir}, 0, process.env.windir);
41-
testCwd({cwd: 'c:\\'}, 0, 'c:\\');
4242
} else {
4343
testCwd({cwd: '/dev'}, 0, '/dev');
44-
testCwd({cwd: '/'}, 0, '/');
4544
}
4645

4746
// Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT

test/parallel/test-child-process-spawnsync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ assert.deepEqual(ret_err.spawnargs, ['bar']);
2020

2121
{
2222
// Test the cwd option
23-
const cwd = common.isWindows ? 'c:\\' : '/';
23+
const cwd = common.rootDir;
2424
const response = common.spawnSyncPwd({cwd});
2525

2626
assert.strictEqual(response.stdout.toString().trim(), cwd);

test/sequential/test-child-process-execsync.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,13 @@ assert.strictEqual(ret, msg + '\n',
6161
'execFileSync encoding result should match');
6262

6363
// Verify that the cwd option works - GH #7824
64-
(function() {
65-
var response;
66-
var cwd;
67-
68-
if (common.isWindows) {
69-
cwd = 'c:\\';
70-
response = execSync('echo %cd%', {cwd: cwd});
71-
} else {
72-
cwd = '/';
73-
response = execSync('pwd', {cwd: cwd});
74-
}
64+
{
65+
const cwd = common.rootDir;
66+
const cmd = common.isWindows ? 'echo %cd%' : 'pwd';
67+
const response = execSync(cmd, {cwd});
7568

7669
assert.strictEqual(response.toString().trim(), cwd);
77-
})();
70+
}
7871

7972
// Verify that stderr is not accessed when stdio = 'ignore' - GH #7966
8073
(function() {

0 commit comments

Comments
 (0)