Skip to content

Commit 041287f

Browse files
committed
fix test problem
1 parent c3691df commit 041287f

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

test/ConfigTestCases.template.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ const describeCases = config => {
326326

327327
const requireCache = Object.create(null);
328328
const esmCache = new Map();
329+
const esmIdentifier = `${category.name}-${testName}-${i}`;
329330
// eslint-disable-next-line no-loop-func
330331
const _require = (
331332
currentDirectory,
@@ -336,7 +337,7 @@ const describeCases = config => {
336337
) => {
337338
if (testConfig === undefined) {
338339
throw new Error(
339-
`_require(${module}) called after all tests have completed`
340+
`_require(${module}) called after all tests from ${category.name} ${testName} have completed`
340341
);
341342
}
342343
if (Array.isArray(module) || /^\.\.?\//.test(module)) {
@@ -382,6 +383,7 @@ const describeCases = config => {
382383
let runInNewContext = false;
383384

384385
const moduleScope = {
386+
console: console,
385387
it: _it,
386388
beforeEach: _beforeEach,
387389
afterEach: _afterEach,
@@ -420,8 +422,8 @@ const describeCases = config => {
420422
let esm = esmCache.get(p);
421423
if (!esm) {
422424
esm = new vm.SourceTextModule(content, {
423-
identifier: p,
424-
url: pathToFileURL(p).href,
425+
identifier: esmIdentifier + "-" + p,
426+
url: pathToFileURL(p).href + "?" + esmIdentifier,
425427
context:
426428
(parentModule && parentModule.context) ||
427429
vm.createContext(moduleScope, {
@@ -453,8 +455,11 @@ const describeCases = config => {
453455
return await asModule(
454456
await _require(
455457
path.dirname(
456-
referencingModule.identifier ||
457-
fileURLToPath(referencingModule.url)
458+
referencingModule.identifier
459+
? referencingModule.identifier.slice(
460+
esmIdentifier.length + 1
461+
)
462+
: fileURLToPath(referencingModule.url)
458463
),
459464
options,
460465
specifier,
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module.exports = {
22
findBundle: function (i, options) {
3-
// In node 10 the ESM part of the test doesn't work
4-
return i === 0 || process.version.startsWith("v10.")
5-
? "./main.js"
6-
: "./module/main.mjs";
3+
return i === 0 ? "./main.js" : "./module/main.mjs";
74
}
85
};

test/configCases/container/0-container-full/webpack.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const common = {
2020
module.exports = [
2121
{
2222
output: {
23-
filename: "[name].js"
23+
filename: "[name].js",
24+
uniqueName: "0-container-full"
2425
},
2526
plugins: [
2627
new ModuleFederationPlugin({
@@ -40,7 +41,8 @@ module.exports = [
4041
outputModule: true
4142
},
4243
output: {
43-
filename: "module/[name].mjs"
44+
filename: "module/[name].mjs",
45+
uniqueName: "0-container-full-mjs"
4446
},
4547
plugins: [
4648
new ModuleFederationPlugin({
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module.exports = {
22
findBundle: function (i, options) {
3-
// In node 10 the ESM part of the test doesn't work
4-
return i === 0 || process.version.startsWith("v10.")
5-
? "./main.js"
6-
: "./module/main.mjs";
3+
return i === 0 ? "./main.js" : "./module/main.mjs";
74
}
85
};

test/configCases/container/1-container-full/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = [
4848
},
4949
output: {
5050
filename: "module/[name].mjs",
51-
uniqueName: "1-container-full"
51+
uniqueName: "1-container-full-mjs"
5252
},
5353
plugins: [
5454
new ModuleFederationPlugin({

0 commit comments

Comments
 (0)