Skip to content

Commit

Permalink
chore: ensure webpack.config.js exist in configCase (web-infra-dev#4837)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi authored Nov 30, 2023
1 parent 246bbdf commit 10cce79
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/rspack/tests/ConfigCase.template.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
27 changes: 27 additions & 0 deletions packages/rspack/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -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}`);
}
}

0 comments on commit 10cce79

Please sign in to comment.