0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/es-module/test-esm-preserve-symlinks.js
Guy Bedford 796f3d0af4
esm: unflag --experimental-modules
PR-URL: https://github.com/nodejs/node/pull/29866
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-11-12 14:04:55 -08:00

39 lines
942 B
JavaScript

'use strict';
const common = require('../common');
const { spawn } = require('child_process');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const tmpDir = tmpdir.path;
const entry = path.join(tmpDir, 'entry.js');
const real = path.join(tmpDir, 'real.js');
const link_absolute_path = path.join(tmpDir, 'link.js');
fs.writeFileSync(entry, `
const assert = require('assert');
global.x = 0;
require('./real.js');
assert.strictEqual(x, 1);
require('./link.js');
assert.strictEqual(x, 2);
`);
fs.writeFileSync(real, 'x++;');
try {
fs.symlinkSync(real, link_absolute_path);
} catch (err) {
if (err.code !== 'EPERM') throw err;
common.skip('insufficient privileges for symlinks');
}
spawn(process.execPath,
['--preserve-symlinks', entry],
{ stdio: 'inherit' }).on('exit', (code) => {
assert.strictEqual(code, 0);
});