From 71ea45028702fcd878e7b086cfd7dd1adfb3c9d2 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Fri, 15 Nov 2024 20:54:46 +0300 Subject: [PATCH] test: fix --- lib/css/CssLoadingRuntimeModule.js | 8 +-- .../css/basic-dynamic-only/test.config.js | 5 ++ .../css/basic-esm-target-node/test.config.js | 5 ++ .../css/basic-esm-target-web/test.config.js | 7 +-- .../css/basic-web-async/test.config.js | 3 ++ test/configCases/css/basic/test.config.js | 3 ++ .../css/conflicting-order/test.config.js | 5 ++ .../css/contenthash/test.config.js | 49 ------------------- .../css/exports-convention/test.config.js | 13 +++++ .../test.config.js | 10 ++++ test/configCases/css/external/test.config.js | 5 ++ .../css/local-ident-name/test.config.js | 15 ++++++ .../css/pseudo-import/test.config.js | 3 ++ .../test.config.js | 5 ++ 14 files changed, 78 insertions(+), 58 deletions(-) create mode 100644 test/configCases/css/basic-dynamic-only/test.config.js create mode 100644 test/configCases/css/basic-esm-target-node/test.config.js create mode 100644 test/configCases/css/conflicting-order/test.config.js delete mode 100644 test/configCases/css/contenthash/test.config.js create mode 100644 test/configCases/css/exports-convention/test.config.js create mode 100644 test/configCases/css/exports-only-generator-options/test.config.js create mode 100644 test/configCases/css/external/test.config.js create mode 100644 test/configCases/css/local-ident-name/test.config.js create mode 100644 test/configCases/css/url-and-asset-module-filename/test.config.js diff --git a/lib/css/CssLoadingRuntimeModule.js b/lib/css/CssLoadingRuntimeModule.js index dea84cac0..d5b371cb7 100644 --- a/lib/css/CssLoadingRuntimeModule.js +++ b/lib/css/CssLoadingRuntimeModule.js @@ -184,7 +184,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { )};` : "// data-webpack is not used as build has no uniqueName", `var loadCssChunkData = ${runtimeTemplate.basicFunction( - "target, link, chunkId", + "target, chunkId", [ `${withHmr ? "var moduleIds = [];" : ""}`, `${ @@ -299,7 +299,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { ]), "} else {", Template.indent([ - `loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`, + `loadCssChunkData(${RuntimeGlobals.moduleFactories}, chunkId);`, "installedChunkData[0]();" ]), "}" @@ -426,7 +426,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { "while(newTags.length) {", Template.indent([ "var info = newTags.pop();", - `var chunkModuleIds = loadCssChunkData(${RuntimeGlobals.moduleFactories}, info[1], info[0]);`, + `var chunkModuleIds = loadCssChunkData(${RuntimeGlobals.moduleFactories}, info[0]);`, `chunkModuleIds.forEach(${runtimeTemplate.expressionFunction( "moduleIds.push(id)", "id" @@ -474,7 +474,7 @@ class CssLoadingRuntimeModule extends RuntimeModule { Template.indent([ "try { if(cssTextKey(oldTag) == cssTextKey(link)) { if(link.parentNode) link.parentNode.removeChild(link); return resolve(); } } catch(e) {}", "var factories = {};", - "loadCssChunkData(factories, link, chunkId);", + "loadCssChunkData(factories, chunkId);", `Object.keys(factories).forEach(${runtimeTemplate.expressionFunction( "updatedModulesList.push(id)", "id" diff --git a/test/configCases/css/basic-dynamic-only/test.config.js b/test/configCases/css/basic-dynamic-only/test.config.js new file mode 100644 index 000000000..b7902f72d --- /dev/null +++ b/test/configCases/css/basic-dynamic-only/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return ["style_css.bundle0.js", "bundle0.js"]; + } +}; diff --git a/test/configCases/css/basic-esm-target-node/test.config.js b/test/configCases/css/basic-esm-target-node/test.config.js new file mode 100644 index 000000000..0c043dd52 --- /dev/null +++ b/test/configCases/css/basic-esm-target-node/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return ["style2_css.bundle0.mjs", "bundle0.mjs"]; + } +}; diff --git a/test/configCases/css/basic-esm-target-web/test.config.js b/test/configCases/css/basic-esm-target-web/test.config.js index 059075728..0c043dd52 100644 --- a/test/configCases/css/basic-esm-target-web/test.config.js +++ b/test/configCases/css/basic-esm-target-web/test.config.js @@ -1,8 +1,5 @@ module.exports = { - moduleScope(scope) { - const link = scope.window.document.createElement("link"); - link.rel = "stylesheet"; - link.href = "bundle0.css"; - scope.window.document.head.appendChild(link); + findBundle: function (i, options) { + return ["style2_css.bundle0.mjs", "bundle0.mjs"]; } }; diff --git a/test/configCases/css/basic-web-async/test.config.js b/test/configCases/css/basic-web-async/test.config.js index 059075728..504f8b6b7 100644 --- a/test/configCases/css/basic-web-async/test.config.js +++ b/test/configCases/css/basic-web-async/test.config.js @@ -1,4 +1,7 @@ module.exports = { + findBundle: function (i, options) { + return ["style2_css.bundle0.js", "bundle0.js"]; + }, moduleScope(scope) { const link = scope.window.document.createElement("link"); link.rel = "stylesheet"; diff --git a/test/configCases/css/basic/test.config.js b/test/configCases/css/basic/test.config.js index 059075728..504f8b6b7 100644 --- a/test/configCases/css/basic/test.config.js +++ b/test/configCases/css/basic/test.config.js @@ -1,4 +1,7 @@ module.exports = { + findBundle: function (i, options) { + return ["style2_css.bundle0.js", "bundle0.js"]; + }, moduleScope(scope) { const link = scope.window.document.createElement("link"); link.rel = "stylesheet"; diff --git a/test/configCases/css/conflicting-order/test.config.js b/test/configCases/css/conflicting-order/test.config.js new file mode 100644 index 000000000..9cebb3990 --- /dev/null +++ b/test/configCases/css/conflicting-order/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return ["css.bundle0.js", "lazy4_js.bundle0.js", "bundle0.js"]; + } +}; diff --git a/test/configCases/css/contenthash/test.config.js b/test/configCases/css/contenthash/test.config.js deleted file mode 100644 index fbe65cee4..000000000 --- a/test/configCases/css/contenthash/test.config.js +++ /dev/null @@ -1,49 +0,0 @@ -const fs = require("fs"); - -let cssBundle; - -module.exports = { - findBundle: function (_, options) { - const jsBundleRegex = new RegExp(/^bundle\..+\.js$/, "i"); - const cssBundleRegex = new RegExp(/^bundle\..+\.css$/, "i"); - const asyncRegex = new RegExp(/^async\..+\.js$/, "i"); - const files = fs.readdirSync(options.output.path); - const jsBundle = files.find(file => jsBundleRegex.test(file)); - - if (!jsBundle) { - throw new Error( - `No file found with correct name (regex: ${ - jsBundleRegex.source - }, files: ${files.join(", ")})` - ); - } - - const async = files.find(file => asyncRegex.test(file)); - - if (!async) { - throw new Error( - `No file found with correct name (regex: ${ - asyncRegex.source - }, files: ${files.join(", ")})` - ); - } - - cssBundle = files.find(file => cssBundleRegex.test(file)); - - if (!cssBundle) { - throw new Error( - `No file found with correct name (regex: ${ - cssBundleRegex.source - }, files: ${files.join(", ")})` - ); - } - - return [jsBundle, async]; - }, - moduleScope(scope) { - const link = scope.window.document.createElement("link"); - link.rel = "stylesheet"; - link.href = cssBundle; - scope.window.document.head.appendChild(link); - } -}; diff --git a/test/configCases/css/exports-convention/test.config.js b/test/configCases/css/exports-convention/test.config.js new file mode 100644 index 000000000..b1dafa854 --- /dev/null +++ b/test/configCases/css/exports-convention/test.config.js @@ -0,0 +1,13 @@ +module.exports = { + findBundle: function (i, options) { + return [ + `style_module_css_as-is.bundle${i}.js`, + `style_module_css_camel-case.bundle${i}.js`, + `style_module_css_camel-case-only.bundle${i}.js`, + `style_module_css_dashes.bundle${i}.js`, + `style_module_css_dashes-only.bundle${i}.js`, + `style_module_css_upper.bundle${i}.js`, + `bundle${i}.js` + ]; + } +}; diff --git a/test/configCases/css/exports-only-generator-options/test.config.js b/test/configCases/css/exports-only-generator-options/test.config.js new file mode 100644 index 000000000..d9ec524ad --- /dev/null +++ b/test/configCases/css/exports-only-generator-options/test.config.js @@ -0,0 +1,10 @@ +module.exports = { + findBundle: function (i, options) { + return [ + "pseudo-export_style_module_css.bundle0.js", + "pseudo-export_style_module_css_module.bundle0.js", + "pseudo-export_style_module_css_exportsOnly.bundle0.js", + "bundle0.js" + ]; + } +}; diff --git a/test/configCases/css/external/test.config.js b/test/configCases/css/external/test.config.js new file mode 100644 index 000000000..656462995 --- /dev/null +++ b/test/configCases/css/external/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return ["125.bundle0.js", "bundle0.js"]; + } +}; diff --git a/test/configCases/css/local-ident-name/test.config.js b/test/configCases/css/local-ident-name/test.config.js new file mode 100644 index 000000000..97c3e830c --- /dev/null +++ b/test/configCases/css/local-ident-name/test.config.js @@ -0,0 +1,15 @@ +module.exports = { + findBundle: function (i, options) { + return [ + `style_module_css.bundle${i}.js`, + `style_module_css_hash.bundle${i}.js`, + `style_module_css_hash-local.bundle${i}.js`, + `style_module_css_path-name-local.bundle${i}.js`, + `style_module_css_file-local.bundle${i}.js`, + `style_module_css_q_f.bundle${i}.js`, + `style_module_css_uniqueName-id-contenthash.bundle${i}.js`, + `style_module_less.bundle${i}.js`, + `bundle${i}.js` + ]; + } +}; diff --git a/test/configCases/css/pseudo-import/test.config.js b/test/configCases/css/pseudo-import/test.config.js index 059075728..f1b96a5a1 100644 --- a/test/configCases/css/pseudo-import/test.config.js +++ b/test/configCases/css/pseudo-import/test.config.js @@ -1,4 +1,7 @@ module.exports = { + findBundle: function (i, options) { + return ["reexport_modules_css.bundle0.js", "bundle0.js"]; + }, moduleScope(scope) { const link = scope.window.document.createElement("link"); link.rel = "stylesheet"; diff --git a/test/configCases/css/url-and-asset-module-filename/test.config.js b/test/configCases/css/url-and-asset-module-filename/test.config.js new file mode 100644 index 000000000..486e49058 --- /dev/null +++ b/test/configCases/css/url-and-asset-module-filename/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return [`index_css.bundle${i}.js`, `bundle${i}.js`]; + } +};