1'use strict'; 2const common = require('../../common'); 3const fs = require('fs'); 4const path = require('path'); 5const assert = require('assert'); 6 7// This test verifies that symlinked native addons can be required multiple 8// times without error. The symlinked module and the non-symlinked module 9// should be the same instance. This expectation was not previously being 10// tested and ended up being broken by https://github.com/nodejs/node/pull/5950. 11 12// This test should pass in Node.js v4 and v5. This test will pass in Node.js 13// with https://github.com/nodejs/node/pull/5950 reverted. 14 15const tmpdir = require('../../common/tmpdir'); 16tmpdir.refresh(); 17 18const addonPath = path.join(__dirname, 'build', common.buildType); 19const addonLink = path.join(tmpdir.path, 'addon'); 20 21try { 22 fs.symlinkSync(addonPath, addonLink, 'dir'); 23} catch (err) { 24 if (err.code !== 'EPERM') throw err; 25 common.skip('module identity test (no privs for symlinks)'); 26} 27 28const sub = require('./submodule'); 29[addonPath, addonLink].forEach((i) => { 30 const mod = require(path.join(i, 'binding.node')); 31 assert.notStrictEqual(mod, null); 32 assert.strictEqual(mod.hello(), 'world'); 33 sub.test(i); // Should not throw. 34}); 35