• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const { spawn } = require('child_process');
5const assert = require('assert');
6const path = require('path');
7const fs = require('fs');
8
9const tmpdir = require('../common/tmpdir');
10tmpdir.refresh();
11const tmpDir = tmpdir.path;
12
13const entry = path.join(tmpDir, 'entry.mjs');
14const real = path.join(tmpDir, 'index.mjs');
15const link_absolute_path = path.join(tmpDir, 'absolute.mjs');
16const link_relative_path = path.join(tmpDir, 'relative.mjs');
17const link_ignore_extension = path.join(tmpDir,
18                                        'ignore_extension.json');
19const link_directory = path.join(tmpDir, 'directory');
20
21fs.writeFileSync(real, 'export default [];');
22fs.writeFileSync(entry, `
23import assert from 'assert';
24import real from './index.mjs';
25import absolute from './absolute.mjs';
26import relative from './relative.mjs';
27import ignoreExtension from './ignore_extension.json';
28
29assert.strictEqual(absolute, real);
30assert.strictEqual(relative, real);
31assert.strictEqual(ignoreExtension, real);
32`);
33
34try {
35  fs.symlinkSync(real, link_absolute_path);
36  fs.symlinkSync(path.basename(real), link_relative_path);
37  fs.symlinkSync(real, link_ignore_extension);
38  fs.symlinkSync(path.dirname(real), link_directory, 'dir');
39} catch (err) {
40  if (err.code !== 'EPERM') throw err;
41  common.skip('insufficient privileges for symlinks');
42}
43
44spawn(process.execPath, [entry],
45      { stdio: 'inherit' }).on('exit', (code) => {
46  assert.strictEqual(code, 0);
47});
48