diff --git a/packages/rspack/tests/ConfigCase.template.ts b/packages/rspack/tests/ConfigCase.template.ts index 52ecfacb50ce..f131f44eabf2 100644 --- a/packages/rspack/tests/ConfigCase.template.ts +++ b/packages/rspack/tests/ConfigCase.template.ts @@ -1,6 +1,7 @@ "use strict"; import { rspack } from "../src"; import assert from "assert"; +import { ensureRspackConfigNotExist, ensureWebpackConfigExist } from "./utils"; const path = require("path"); const fs = require("graceful-fs"); @@ -73,10 +74,11 @@ export const describeCases = config => { for (const testName of category.tests) { // eslint-disable-next-line no-loop-func const testDirectory = path.join(casesPath, category.name, testName); + + ensureRspackConfigNotExist(testDirectory); + ensureWebpackConfigExist(testDirectory); + const configFile = path.join(testDirectory, "webpack.config.js"); - if (!fs.existsSync(configFile)) { - continue; - } describe(testName, function () { const filterPath = path.join(testDirectory, "test.filter.js"); if ( diff --git a/packages/rspack/tests/configCases/warnings/not-fully-specified/fully-specified.mjs b/packages/rspack/tests/cases/warnings/not-fully-specified/fully-specified.mjs similarity index 100% rename from packages/rspack/tests/configCases/warnings/not-fully-specified/fully-specified.mjs rename to packages/rspack/tests/cases/warnings/not-fully-specified/fully-specified.mjs diff --git a/packages/rspack/tests/configCases/warnings/not-fully-specified/index.js b/packages/rspack/tests/cases/warnings/not-fully-specified/index.js similarity index 100% rename from packages/rspack/tests/configCases/warnings/not-fully-specified/index.js rename to packages/rspack/tests/cases/warnings/not-fully-specified/index.js diff --git a/packages/rspack/tests/configCases/warnings/not-fully-specified/not-fully-specified.mjs b/packages/rspack/tests/cases/warnings/not-fully-specified/not-fully-specified.mjs similarity index 100% rename from packages/rspack/tests/configCases/warnings/not-fully-specified/not-fully-specified.mjs rename to packages/rspack/tests/cases/warnings/not-fully-specified/not-fully-specified.mjs diff --git a/packages/rspack/tests/configCases/worker/not-fully-specified-by-default/a.js b/packages/rspack/tests/cases/worker/not-fully-specified-by-default/a.js similarity index 100% rename from packages/rspack/tests/configCases/worker/not-fully-specified-by-default/a.js rename to packages/rspack/tests/cases/worker/not-fully-specified-by-default/a.js diff --git a/packages/rspack/tests/configCases/worker/not-fully-specified-by-default/index.js b/packages/rspack/tests/cases/worker/not-fully-specified-by-default/index.js similarity index 100% rename from packages/rspack/tests/configCases/worker/not-fully-specified-by-default/index.js rename to packages/rspack/tests/cases/worker/not-fully-specified-by-default/index.js diff --git a/packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/src/index.js b/packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/index.js similarity index 77% rename from packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/src/index.js rename to packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/index.js index 6a2908a38f2c..f6e6d524febd 100644 --- a/packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/src/index.js +++ b/packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/index.js @@ -1,7 +1,7 @@ import { Button } from "aaaaa"; import fs from "fs"; -describe("should generate css successfully", () => { +it("should generate css successfully", () => { const dir = fs.readdirSync(__dirname); expect(dir).toStrictEqual(["main.css", "main.js"]); expect(Button).toBe("button"); diff --git a/packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/rspack.config.js b/packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/webpack.config.js similarity index 100% rename from packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/rspack.config.js rename to packages/rspack/tests/configCases/builtin-swc-loader/issue-4597/webpack.config.js diff --git a/packages/rspack/tests/configCases/hooks/issue-4395/rspack.config.js b/packages/rspack/tests/configCases/hooks/issue-4395/webpack.config.js similarity index 100% rename from packages/rspack/tests/configCases/hooks/issue-4395/rspack.config.js rename to packages/rspack/tests/configCases/hooks/issue-4395/webpack.config.js diff --git a/packages/rspack/tests/utils.ts b/packages/rspack/tests/utils.ts new file mode 100644 index 000000000000..4cee1993661d --- /dev/null +++ b/packages/rspack/tests/utils.ts @@ -0,0 +1,27 @@ +import path from "path"; +import fs from "fs"; + +// TODO: It's better to use `Promise.all` +function configFileExist(dir: string, config: "webpack" | "rspack") { + const files = ["js", "ts", "mjs", "mts"].map( + ext => `${config}.config.${ext}` + ); + return files.some(file => { + const p = path.resolve(dir, file); + return fs.existsSync(p) && fs.lstatSync(p).isFile(); + }); +} + +export function ensureWebpackConfigExist(testCaseDir: string) { + const exist = configFileExist(testCaseDir, "webpack"); + if (!exist) { + throw Error(`not found webpack.config.js in ${testCaseDir}`); + } +} + +export function ensureRspackConfigNotExist(testCaseDir: string) { + const exist = configFileExist(testCaseDir, "rspack"); + if (exist) { + throw Error(`rspack config file should not exist in ${testCaseDir}`); + } +}