11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../../common');
31cb0ef41Sopenharmony_ciconst fs = require('fs');
41cb0ef41Sopenharmony_ciconst path = require('path');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// This test verifies that symlinked native addons can be required multiple
81cb0ef41Sopenharmony_ci// times without error. The symlinked module and the non-symlinked module
91cb0ef41Sopenharmony_ci// should be the same instance. This expectation was not previously being
101cb0ef41Sopenharmony_ci// tested and ended up being broken by https://github.com/nodejs/node/pull/5950.
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// This test should pass in Node.js v4 and v5. This test will pass in Node.js
131cb0ef41Sopenharmony_ci// with https://github.com/nodejs/node/pull/5950 reverted.
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst tmpdir = require('../../common/tmpdir');
161cb0ef41Sopenharmony_citmpdir.refresh();
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst addonPath = path.join(__dirname, 'build', common.buildType);
191cb0ef41Sopenharmony_ciconst addonLink = path.join(tmpdir.path, 'addon');
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_citry {
221cb0ef41Sopenharmony_ci  fs.symlinkSync(addonPath, addonLink, 'dir');
231cb0ef41Sopenharmony_ci} catch (err) {
241cb0ef41Sopenharmony_ci  if (err.code !== 'EPERM') throw err;
251cb0ef41Sopenharmony_ci  common.skip('module identity test (no privs for symlinks)');
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciconst sub = require('./submodule');
291cb0ef41Sopenharmony_ci[addonPath, addonLink].forEach((i) => {
301cb0ef41Sopenharmony_ci  const mod = require(path.join(i, 'binding.node'));
311cb0ef41Sopenharmony_ci  assert.notStrictEqual(mod, null);
321cb0ef41Sopenharmony_ci  assert.strictEqual(mod.hello(), 'world');
331cb0ef41Sopenharmony_ci  sub.test(i); // Should not throw.
341cb0ef41Sopenharmony_ci});
35