node/test/addons/symlinked-module/test.js
James M Snell 5d38d543cd src,module: add --preserve-symlinks command line flag
Add the `--preserve-symlinks` flag. This makes the changes added
in #5950 conditional. By default the old behavior is used. With
the flag set, symlinks are preserved, switching to the new
behavior. This should be considered to be a temporary solution
until we figure out how to solve the symlinked peer dependency
problem in a more general way that does not break everything
else.

Additional test cases are included.

PR-URL: https://github.com/nodejs/node/pull/6537
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-13 11:43:47 -07:00

35 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../../common');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
// This test verifies that symlinked native modules can be required multiple
// times without error. The symlinked module and the non-symlinked module
// should be the same instance. This expectation was not previously being
// tested and ended up being broken by https://github.com/nodejs/node/pull/5950.
// This test should pass in Node.js v4 and v5. This test will pass in Node.js
// with https://github.com/nodejs/node/pull/5950 reverted.
common.refreshTmpDir();
const addonPath = path.join(__dirname, 'build', 'Release');
const addonLink = path.join(common.tmpDir, 'addon');
try {
fs.symlinkSync(addonPath, addonLink);
} catch (err) {
if (err.code !== 'EPERM') throw err;
common.skip('module identity test (no privs for symlinks)');
return;
}
const sub = require('./submodule');
[addonPath, addonLink].forEach((i) => {
const mod = require(path.join(i, 'binding.node'));
assert.notStrictEqual(mod, null);
assert.strictEqual(mod.hello(), 'world');
assert.doesNotThrow(() => sub.test(i));
});