test: add cwd ENOENT known issue test · nodejs/node@d8f5637
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+}