Skip to content

Commit 4fc1199

Browse files
committed
test: add cwd ENOENT known issue test
If the current working directory is removed, Node cannot start normally because the module system calls uv_cwd(). Refs: #12022 PR-URL: #12343 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6331b63 commit 4fc1199

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
// Refs: https://github.com/nodejs/node/pull/12022
3+
// If the cwd is deleted, Node cannot run files because the module system
4+
// relies on uv_cwd(). The -e and -p flags still work though.
5+
const common = require('../common');
6+
const assert = require('assert');
7+
8+
if (common.isSunOS || common.isWindows || common.isAix) {
9+
// The current working directory cannot be removed on these platforms.
10+
// Change this to common.skip() when this is no longer a known issue test.
11+
assert.fail('cannot rmdir current working directory');
12+
return;
13+
}
14+
15+
const cp = require('child_process');
16+
const fs = require('fs');
17+
18+
if (process.argv[2] === 'child') {
19+
// Do nothing.
20+
} else {
21+
common.refreshTmpDir();
22+
const dir = fs.mkdtempSync(common.tmpDir + '/');
23+
process.chdir(dir);
24+
fs.rmdirSync(dir);
25+
assert.throws(process.cwd,
26+
/^Error: ENOENT: no such file or directory, uv_cwd$/);
27+
28+
const r = cp.spawnSync(process.execPath, [__filename, 'child']);
29+
30+
assert.strictEqual(r.status, 0);
31+
assert.strictEqual(r.signal, null);
32+
assert.strictEqual(r.stdout.toString().trim(), '');
33+
assert.strictEqual(r.stderr.toString().trim(), '');
34+
}

0 commit comments

Comments
 (0)