Skip to content

Commit b854055

Browse files
ci: node.js@24 and rewrite ts tests (#4456)
1 parent d8ab7a7 commit b854055

File tree

15 files changed

+89
-80
lines changed

15 files changed

+89
-80
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
3-
"module": "esnext",
4-
"allowSyntheticDefaultImports": true
3+
"target": "esnext",
4+
"allowImportingTsExtensions": true,
5+
"rewriteRelativeImportExtensions": true,
6+
"module": "esnext"
57
}
68
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// eslint-disable-next-line n/no-unpublished-require
2+
const { run } = require("../../../utils/test-utils");
3+
const { existsSync } = require("fs");
4+
const { resolve } = require("path");
5+
6+
describe("webpack cli", () => {
7+
it("should support typescript esnext file", async () => {
8+
const [major] = process.versions.node.split(".").map(Number);
9+
const { exitCode, stderr, stdout } = await run(
10+
__dirname,
11+
["-c", "./webpack.config.ts", "--disable-interpret"],
12+
{
13+
env: {
14+
NODE_NO_WARNINGS: 1,
15+
// Due nyc logic
16+
WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true,
17+
},
18+
// Fallback to `ts-node/esm` for old Node.js versions
19+
nodeOptions: major >= 24 ? [] : ["--experimental-loader=ts-node/esm"],
20+
},
21+
);
22+
23+
expect(stderr).toBeFalsy(); // Deprecation warning logs on stderr
24+
expect(stdout).toBeTruthy();
25+
expect(exitCode).toBe(0);
26+
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
27+
});
28+
});

test/build/config-format/typescript-mjs-using-nodejs/webpack.config.mts renamed to test/build/config-format/typescript-cjs-using-nodejs/webpack.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable node/no-unsupported-features/es-syntax */
21
import * as path from "path";
32

43
// cspell:ignore elopment

test/build/config-format/typescript-commonjs-using-nodejs/typescript.test.js

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
3-
"module": "esnext",
4-
"allowSyntheticDefaultImports": true
3+
"target": "esnext",
4+
"allowImportingTsExtensions": true,
5+
"rewriteRelativeImportExtensions": true,
6+
"module": "esnext"
57
}
68
}

test/build/config-format/typescript-mjs-using-nodejs/typescript.test.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ const { resolve } = require("path");
55

66
describe("webpack cli", () => {
77
it("should support typescript esnext file", async () => {
8-
const [major, minor] = process.versions.node.split(".").map(Number);
9-
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.mts"], {
10-
env: { NODE_NO_WARNINGS: 1 },
11-
// Fallback to `ts-node/esm` for old Node.js versions
12-
nodeOptions: major >= 22 && minor >= 6 ? [] : ["--experimental-loader=ts-node/esm"],
13-
});
8+
const [major] = process.versions.node.split(".").map(Number);
9+
const { exitCode, stderr, stdout } = await run(
10+
__dirname,
11+
["-c", "./webpack.config.ts", "--disable-interpret"],
12+
{
13+
env: {
14+
NODE_NO_WARNINGS: 1,
15+
// Due nyc logic
16+
WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true,
17+
},
18+
// Fallback to `ts-node/esm` for old Node.js versions
19+
nodeOptions: major >= 24 ? [] : ["--experimental-loader=ts-node/esm"],
20+
},
21+
);
1422

1523
expect(stderr).toBeFalsy(); // Deprecation warning logs on stderr
1624
expect(stdout).toBeTruthy();

test/build/config-format/typescript-cjs-using-nodejs/webpack.config.cts renamed to test/build/config-format/typescript-mjs-using-nodejs/webpack.config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* eslint-disable node/no-unsupported-features/es-syntax */
2-
const path = require("path");
1+
import * as path from "path";
32

43
// cspell:ignore elopment
54
const mode: string = "dev" + "elopment";
@@ -12,4 +11,4 @@ const config = {
1211
},
1312
};
1413

15-
module.exports = config;
14+
export default config;

test/build/config-format/typescript-ts-node-loader/typescript.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ describe("webpack cli", () => {
77
it("should support typescript esnext file", async () => {
88
const [major, minor] = process.versions.node.split(".").map(Number);
99
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"], {
10-
env: { NODE_NO_WARNINGS: 1 },
10+
env: {
11+
NODE_NO_WARNINGS: 1,
12+
// Due nyc logic
13+
WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true,
14+
},
1115
nodeOptions:
1216
major >= 22 && minor >= 6
1317
? ["--no-experimental-strip-types", "--experimental-loader=ts-node/esm"]

test/build/config-format/typescript-using-interpret/main.ts

-1
This file was deleted.

test/build/config-format/typescript-using-interpret/package.json

-3
This file was deleted.

test/build/config-format/typescript-using-interpret/tsconfig.json

-5
This file was deleted.

test/build/config-format/typescript-using-interpret/typescript.test.js

-19
This file was deleted.

test/build/config-format/typescript-using-interpret/webpack.config.ts

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
3-
"module": "esnext",
4-
"allowSyntheticDefaultImports": true
3+
"target": "esnext",
4+
"allowImportingTsExtensions": true,
5+
"rewriteRelativeImportExtensions": true,
6+
"module": "esnext"
57
}
68
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// eslint-disable-next-line n/no-unpublished-require
2+
const { run } = require("../../../utils/test-utils");
3+
const { existsSync } = require("fs");
4+
const { resolve } = require("path");
5+
6+
describe("webpack cli", () => {
7+
it("should support typescript esnext file", async () => {
8+
const [major] = process.versions.node.split(".").map(Number);
9+
const { exitCode, stderr, stdout } = await run(
10+
__dirname,
11+
["-c", "./webpack.config.ts", "--disable-interpret"],
12+
{
13+
env: {
14+
NODE_NO_WARNINGS: 1,
15+
// Due nyc logic
16+
WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true,
17+
},
18+
// Fallback to `ts-node/esm` for old Node.js versions
19+
nodeOptions: major >= 24 ? [] : ["--experimental-loader=ts-node/esm"],
20+
},
21+
);
22+
23+
expect(stderr).toBeFalsy(); // Deprecation warning logs on stderr
24+
expect(stdout).toBeTruthy();
25+
expect(exitCode).toBe(0);
26+
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
27+
});
28+
});

0 commit comments

Comments
 (0)