diff --git a/test/ConfigTestCases.template.js b/test/ConfigTestCases.template.js index 9f4bd4c5186..3dcdbecb89c 100644 --- a/test/ConfigTestCases.template.js +++ b/test/ConfigTestCases.template.js @@ -326,6 +326,7 @@ const describeCases = config => { const requireCache = Object.create(null); const esmCache = new Map(); + const esmIdentifier = `${category.name}-${testName}-${i}`; // eslint-disable-next-line no-loop-func const _require = ( currentDirectory, @@ -336,7 +337,7 @@ const describeCases = config => { ) => { if (testConfig === undefined) { throw new Error( - `_require(${module}) called after all tests have completed` + `_require(${module}) called after all tests from ${category.name} ${testName} have completed` ); } if (Array.isArray(module) || /^\.\.?\//.test(module)) { @@ -382,6 +383,7 @@ const describeCases = config => { let runInNewContext = false; const moduleScope = { + console: console, it: _it, beforeEach: _beforeEach, afterEach: _afterEach, @@ -420,8 +422,8 @@ const describeCases = config => { let esm = esmCache.get(p); if (!esm) { esm = new vm.SourceTextModule(content, { - identifier: p, - url: pathToFileURL(p).href, + identifier: esmIdentifier + "-" + p, + url: pathToFileURL(p).href + "?" + esmIdentifier, context: (parentModule && parentModule.context) || vm.createContext(moduleScope, { @@ -453,8 +455,11 @@ const describeCases = config => { return await asModule( await _require( path.dirname( - referencingModule.identifier || - fileURLToPath(referencingModule.url) + referencingModule.identifier + ? referencingModule.identifier.slice( + esmIdentifier.length + 1 + ) + : fileURLToPath(referencingModule.url) ), options, specifier, diff --git a/test/configCases/container/0-container-full/test.config.js b/test/configCases/container/0-container-full/test.config.js index a11224de659..2d0d66fd4c0 100644 --- a/test/configCases/container/0-container-full/test.config.js +++ b/test/configCases/container/0-container-full/test.config.js @@ -1,8 +1,5 @@ module.exports = { findBundle: function (i, options) { - // In node 10 the ESM part of the test doesn't work - return i === 0 || process.version.startsWith("v10.") - ? "./main.js" - : "./module/main.mjs"; + return i === 0 ? "./main.js" : "./module/main.mjs"; } }; diff --git a/test/configCases/container/0-container-full/webpack.config.js b/test/configCases/container/0-container-full/webpack.config.js index da13a30272a..3fe8d8bab2c 100644 --- a/test/configCases/container/0-container-full/webpack.config.js +++ b/test/configCases/container/0-container-full/webpack.config.js @@ -20,7 +20,8 @@ const common = { module.exports = [ { output: { - filename: "[name].js" + filename: "[name].js", + uniqueName: "0-container-full" }, plugins: [ new ModuleFederationPlugin({ @@ -40,7 +41,8 @@ module.exports = [ outputModule: true }, output: { - filename: "module/[name].mjs" + filename: "module/[name].mjs", + uniqueName: "0-container-full-mjs" }, plugins: [ new ModuleFederationPlugin({ diff --git a/test/configCases/container/1-container-full/test.config.js b/test/configCases/container/1-container-full/test.config.js index a11224de659..2d0d66fd4c0 100644 --- a/test/configCases/container/1-container-full/test.config.js +++ b/test/configCases/container/1-container-full/test.config.js @@ -1,8 +1,5 @@ module.exports = { findBundle: function (i, options) { - // In node 10 the ESM part of the test doesn't work - return i === 0 || process.version.startsWith("v10.") - ? "./main.js" - : "./module/main.mjs"; + return i === 0 ? "./main.js" : "./module/main.mjs"; } }; diff --git a/test/configCases/container/1-container-full/webpack.config.js b/test/configCases/container/1-container-full/webpack.config.js index a3a3d527b4d..049f843e7eb 100644 --- a/test/configCases/container/1-container-full/webpack.config.js +++ b/test/configCases/container/1-container-full/webpack.config.js @@ -48,7 +48,7 @@ module.exports = [ }, output: { filename: "module/[name].mjs", - uniqueName: "1-container-full" + uniqueName: "1-container-full-mjs" }, plugins: [ new ModuleFederationPlugin({