Skip to content

Commit

Permalink
fix test problem
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Nov 25, 2021
1 parent c3691df commit 041287f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
15 changes: 10 additions & 5 deletions test/ConfigTestCases.template.js
Expand Up @@ -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,
Expand All @@ -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)) {
Expand Down Expand Up @@ -382,6 +383,7 @@ const describeCases = config => {
let runInNewContext = false;

const moduleScope = {
console: console,
it: _it,
beforeEach: _beforeEach,
afterEach: _afterEach,
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions 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";
}
};
6 changes: 4 additions & 2 deletions test/configCases/container/0-container-full/webpack.config.js
Expand Up @@ -20,7 +20,8 @@ const common = {
module.exports = [
{
output: {
filename: "[name].js"
filename: "[name].js",
uniqueName: "0-container-full"
},
plugins: [
new ModuleFederationPlugin({
Expand All @@ -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({
Expand Down
5 changes: 1 addition & 4 deletions 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";
}
};
Expand Up @@ -48,7 +48,7 @@ module.exports = [
},
output: {
filename: "module/[name].mjs",
uniqueName: "1-container-full"
uniqueName: "1-container-full-mjs"
},
plugins: [
new ModuleFederationPlugin({
Expand Down

0 comments on commit 041287f

Please sign in to comment.