forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-process-cwd-deleted-dir.js
More file actions
44 lines (37 loc) · 1.09 KB
/
test-process-cwd-deleted-dir.js
File metadata and controls
44 lines (37 loc) · 1.09 KB
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
35
36
37
38
39
40
41
42
43
44
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
if (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi) {
// The current working directory cannot be removed on these platforms.
common.skip('cannot rmdir current working directory');
}
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
// Create a temporary directory
const testDir = path.join(tmpdir.path, 'test-cwd-deleted');
fs.mkdirSync(testDir);
// Save original cwd
const originalCwd = process.cwd();
try {
// Change to the test directory
process.chdir(testDir);
// Delete the directory while we're in it
fs.rmdirSync(testDir);
// Verify that process.cwd() throws with improved error message
assert.throws(
() => process.cwd(),
{
code: 'ENOENT',
message: /process\.cwd\(\) failed: current working directory no longer exists/
}
);
} finally {
// Restore original cwd for cleanup
try {
process.chdir(originalCwd);
} catch {
// Ignore errors if we can't change back
}
}