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