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.js'); 14const real = path.join(tmpDir, 'real.js'); 15const link_absolute_path = path.join(tmpDir, 'link.js'); 16 17fs.writeFileSync(entry, ` 18const assert = require('assert'); 19global.x = 0; 20require('./real.js'); 21assert.strictEqual(x, 1); 22require('./link.js'); 23assert.strictEqual(x, 2); 24`); 25fs.writeFileSync(real, 'x++;'); 26 27try { 28 fs.symlinkSync(real, link_absolute_path); 29} catch (err) { 30 if (err.code !== 'EPERM') throw err; 31 common.skip('insufficient privileges for symlinks'); 32} 33 34spawn(process.execPath, 35 ['--preserve-symlinks', entry], 36 { stdio: 'inherit' }).on('exit', (code) => { 37 assert.strictEqual(code, 0); 38}); 39