• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
5const common = require('../common');
6const assert = require('assert');
7
8if (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}
13
14const cp = require('child_process');
15const fs = require('fs');
16
17if (process.argv[2] === 'child') {
18  // Do nothing.
19} else {
20  const tmpdir = require('../common/tmpdir');
21  tmpdir.refresh();
22  const dir = fs.mkdtempSync(`${tmpdir.path}/`);
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}
35