diff --git a/test/fixtures/cjs-module-wrap.js b/test/fixtures/cjs-module-wrap.js index 2e11cc1a3b3..4a3114c5f1e 100644 --- a/test/fixtures/cjs-module-wrap.js +++ b/test/fixtures/cjs-module-wrap.js @@ -1,3 +1,4 @@ +'use strict'; const assert = require('assert'); const m = require('module'); diff --git a/test/fixtures/cjs-module-wrapper.js b/test/fixtures/cjs-module-wrapper.js new file mode 100644 index 00000000000..b4e73682af8 --- /dev/null +++ b/test/fixtures/cjs-module-wrapper.js @@ -0,0 +1,23 @@ +'use strict'; +const assert = require('assert'); +const m = require('module'); + +global.mwc = 0; + +const originalWrapper = m.wrapper; +const patchedWrapper = {...m.wrapper}; + +patchedWrapper[0] += 'global.mwc = (global.mwc || 0 ) + 1'; + +// Storing original version of wrapper function +m.wrapper = patchedWrapper; + +require('./not-main-module.js'); + +assert.strictEqual(mwc, 1); + +// Restoring original wrapper function +m.wrapper = originalWrapper; +// Cleaning require cache +delete require.cache[require.resolve('./not-main-module.js')]; +delete global.mwc; diff --git a/test/parallel/test-module-wrap.js b/test/parallel/test-module-wrap.js index 639300cb6af..367307e4a79 100644 --- a/test/parallel/test-module-wrap.js +++ b/test/parallel/test-module-wrap.js @@ -4,6 +4,6 @@ const fixtures = require('../common/fixtures'); const { execFileSync } = require('child_process'); const cjsModuleWrapTest = fixtures.path('cjs-module-wrap.js'); -const node = process.argv[0]; +const node = process.execPath; execFileSync(node, [cjsModuleWrapTest], { stdio: 'pipe' }); diff --git a/test/parallel/test-module-wrapper.js b/test/parallel/test-module-wrapper.js new file mode 100644 index 00000000000..39e6d734f4f --- /dev/null +++ b/test/parallel/test-module-wrapper.js @@ -0,0 +1,9 @@ +'use strict'; +require('../common'); +const fixtures = require('../common/fixtures'); +const { execFileSync } = require('child_process'); + +const cjsModuleWrapTest = fixtures.path('cjs-module-wrapper.js'); +const node = process.execPath; + +execFileSync(node, [cjsModuleWrapTest], { stdio: 'pipe' });