Skip to content

Commit 7be1e0a

Browse files
rpgeeganagetargos
authored andcommitted
fs: added tests for util file preprocessSymlinkDestination
PR-URL: #27468 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Masashi Hirano <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 33fead3 commit 7be1e0a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/parallel/test-internal-fs.js

+39
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
const common = require('../common');
5+
const assert = require('assert');
56
const fs = require('internal/fs/utils');
67

78
// Valid encodings and no args should not throw.
@@ -12,3 +13,41 @@ common.expectsError(
1213
() => fs.assertEncoding('foo'),
1314
{ code: 'ERR_INVALID_OPT_VALUE_ENCODING', type: TypeError }
1415
);
16+
17+
// Test junction symlinks
18+
{
19+
const pathString = 'c:\\test1';
20+
const linkPathString = '\\test2';
21+
22+
const preprocessSymlinkDestination = fs.preprocessSymlinkDestination(
23+
pathString,
24+
'junction',
25+
linkPathString
26+
);
27+
28+
if (process.platform === 'win32') {
29+
assert.strictEqual(/^\\\\\?\\/.test(preprocessSymlinkDestination), true);
30+
} else {
31+
assert.strictEqual(preprocessSymlinkDestination, pathString);
32+
}
33+
}
34+
35+
// Test none junction symlinks
36+
{
37+
const pathString = 'c:\\test1';
38+
const linkPathString = '\\test2';
39+
40+
const preprocessSymlinkDestination = fs.preprocessSymlinkDestination(
41+
pathString,
42+
undefined,
43+
linkPathString
44+
);
45+
46+
if (process.platform === 'win32') {
47+
// There should not be any forward slashes
48+
assert.strictEqual(
49+
/\//.test(preprocessSymlinkDestination), false);
50+
} else {
51+
assert.strictEqual(preprocessSymlinkDestination, pathString);
52+
}
53+
}

0 commit comments

Comments
 (0)