-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-fs-cp-async-verbatim-dir-symlinks-with-filter.mjs
More file actions
46 lines (41 loc) · 1.69 KB
/
test-fs-cp-async-verbatim-dir-symlinks-with-filter.mjs
File metadata and controls
46 lines (41 loc) · 1.69 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
45
46
// This tests that cp with verbatimSymlinks and filter preserves
// the directory symlink type on Windows (does not create a file symlink).
import { mustNotMutateObjectDeep, isWindows } from '../common/index.mjs';
import { nextdir } from '../common/fs.js';
import assert from 'node:assert';
import {
mkdirSync,
writeFileSync,
symlinkSync,
readlinkSync,
readdirSync,
statSync,
} from 'node:fs';
import { cp } from 'node:fs/promises';
import { join } from 'node:path';
import tmpdir from '../common/tmpdir.js';
tmpdir.refresh();
// Setup source with a relative directory symlink
const src = nextdir();
mkdirSync(join(src, 'packages', 'my-lib'), mustNotMutateObjectDeep({ recursive: true }));
writeFileSync(join(src, 'packages', 'my-lib', 'index.js'), 'module.exports = "hello"');
mkdirSync(join(src, 'linked'), mustNotMutateObjectDeep({ recursive: true }));
symlinkSync(join('..', 'packages', 'my-lib'), join(src, 'linked', 'my-lib'), 'dir');
// Copy with verbatimSymlinks: true AND a filter function
const dest = nextdir();
await cp(src, dest, mustNotMutateObjectDeep({
recursive: true,
verbatimSymlinks: true,
filter: () => true,
}));
// Verify the symlink target is preserved verbatim
const link = readlinkSync(join(dest, 'linked', 'my-lib'));
if (isWindows) {
assert.strictEqual(link.toLowerCase(), join('..', 'packages', 'my-lib').toLowerCase());
} else {
assert.strictEqual(link, join('..', 'packages', 'my-lib'));
}
// Verify the symlink works as a directory (not a file symlink)
const destSymlink = join(dest, 'linked', 'my-lib');
assert.ok(statSync(destSymlink).isDirectory(), 'symlink target should be accessible as a directory');
assert.deepStrictEqual(readdirSync(destSymlink), ['index.js']);