Skip to content

Commit a199bc3

Browse files
test: refactor config format test + more (#4684)
1 parent 20bc478 commit a199bc3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+393
-215
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default defineConfig([
1515
"test/build/config/error-array/webpack.config.js",
1616
"test/build/config-format/esm-require-await/webpack.config.js",
1717
"test/configtest/with-config-path/syntax-error.config.js",
18-
"test/build/config-format/esm-require/webpack.config.js",
18+
"test/build/config-format/auto/webpack.config.js",
1919
]),
2020
{
2121
extends: [config],
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { existsSync } from "node:fs";
2+
import { dirname, resolve } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
import { run } from "../../../utils/test-utils.js";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
9+
describe("auto loading different formats of configuration", () => {
10+
it("should support configuration (Node.js build-in support)", async () => {
11+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"], {
12+
nodeOptions: [],
13+
});
14+
15+
expect(stderr).toContain(
16+
"Reparsing as ES module because module syntax was detected. This incurs a performance overhead.",
17+
);
18+
expect(stdout).toBeTruthy();
19+
expect(exitCode).toBe(0);
20+
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
21+
});
22+
23+
it("should support configuration (Node.js build-in support) with `mjs` extension", async () => {
24+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.mjs"], {
25+
nodeOptions: [],
26+
});
27+
28+
expect(stderr).toBeFalsy();
29+
expect(stdout).toBeTruthy();
30+
expect(exitCode).toBe(0);
31+
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
32+
});
33+
34+
it("should support configuration (Node.js build-in support) with `cjs` extension", async () => {
35+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.cjs"], {
36+
nodeOptions: [],
37+
});
38+
39+
expect(stderr).toBeFalsy();
40+
expect(stdout).toBeTruthy();
41+
expect(exitCode).toBe(0);
42+
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
43+
});
44+
});

test/build/config-format/typescript-cjs-using-nodejs/main.ts renamed to test/build/config-format/auto/main.js

File renamed without changes.

test/build/config-format/typescript-mjs-using-nodejs/package.json renamed to test/build/config-format/auto/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"type": "module",
32
"engines": {
43
"node": ">=18.12.0"
54
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require("node:path");
2+
3+
const mode = "development";
4+
const config = {
5+
mode,
6+
entry: "./main.js",
7+
output: {
8+
path: path.resolve("dist"),
9+
filename: "foo.bundle.js",
10+
},
11+
};
12+
13+
module.exports = config;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as path from "node:path";
2+
3+
const mode = "development";
4+
const config = {
5+
mode,
6+
entry: "./main.js",
7+
output: {
8+
path: path.resolve("dist"),
9+
filename: "foo.bundle.js",
10+
},
11+
};
12+
13+
export default config;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as path from "node:path";
2+
3+
const mode = "development";
4+
const config = {
5+
mode,
6+
entry: "./main.js",
7+
output: {
8+
path: path.resolve("dist"),
9+
filename: "foo.bundle.js",
10+
},
11+
};
12+
13+
export default config;

test/build/config-format/disable-interpret/disable-interpret.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ describe("webpack cli", () => {
2121
});
2222

2323
it("should log error without transpilation", async () => {
24-
const { exitCode, stderr, stdout } = await run(__dirname, ["--disable-interpret"]);
24+
const [major] = process.versions.node.split(".").map(Number);
25+
const { exitCode, stderr, stdout } = await run(__dirname, ["--disable-interpret"], {
26+
nodeOptions: [
27+
// Disable typescript strip types for tests
28+
...(major >= 24 ? ["--no-experimental-strip-types"] : []),
29+
],
30+
});
2531

2632
expect(exitCode).toBe(2);
2733
expect(stderr).toContain(`Failed to load '${resolve(__dirname, "webpack.config.ts")}' config`);

test/build/config-format/esm-require-await/index.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/build/config-format/esm-require/index.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)