2017-06-06 00:44:56 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const { spawn } = require('child_process');
|
|
|
|
const assert = require('assert');
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
2017-12-25 06:38:11 +00:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
const tmpDir = tmpdir.path;
|
2017-06-06 00:44:56 +00:00
|
|
|
|
|
|
|
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,
|
2019-10-11 21:57:13 +00:00
|
|
|
['--preserve-symlinks', entry],
|
2017-06-06 00:44:56 +00:00
|
|
|
{ stdio: 'inherit' }).on('exit', (code) => {
|
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
});
|