test: verify multiple init via well-known symbol

Re-`require()` the addon after clearing its cache to ensure that it is
re-initialized via the well-known symbol.

PR-URL: https://github.com/nodejs/node/pull/19875
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Gabriel Schulhof 2018-04-07 22:26:08 -04:00
parent 0bd3da15a0
commit 244af7a9d5

View File

@ -1,6 +1,13 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
const binding = require(bindingPath);
assert.strictEqual(binding.hello(), 'world');
console.log('binding.hello() =', binding.hello());
// Test multiple loading of the same module.
delete require.cache[bindingPath];
const rebinding = require(bindingPath);
assert.strictEqual(rebinding.hello(), 'world');
assert.notStrictEqual(binding.hello, rebinding.hello);