• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3
4require('../common');
5const assert = require('assert');
6const fs = require('internal/fs/utils');
7
8// Valid encodings and no args should not throw.
9fs.assertEncoding();
10fs.assertEncoding('utf8');
11
12assert.throws(
13  () => fs.assertEncoding('foo'),
14  { code: 'ERR_INVALID_OPT_VALUE_ENCODING', name: 'TypeError' }
15);
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}
54