Replace ts-jest with @swc/jest for TypeScript test transforms - #313
Conversation
Agent-Logs-Url: https://github.com/USTC-KnowledgeComputingLab/ds/sessions/d8688cd9-2efc-4773-acb9-b665cf6559cb Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR replaces ts-jest with @swc/jest for transforming TypeScript during Jest runs to avoid tsc-triggered failures (notably TS5107 on deprecated moduleResolution modes) while keeping the Jest setup largely unchanged.
Changes:
- Swaps Jest’s TypeScript transform from
ts-jestto@swc/jest(root +egg/). - Updates devDependencies to remove
ts-jestand add@swc/core+@swc/jest(root +egg/), with corresponding lockfile updates.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Replaces ts-jest devDependency with @swc/core and @swc/jest. |
| package-lock.json | Lockfile updates reflecting removal of ts-jest and addition of SWC packages. |
| jest.config.mjs | Switches transform to @swc/jest. |
| egg/package.json | Mirrors root dependency change for the egg/ package. |
| egg/package-lock.json | Mirrors root lockfile changes for egg/. |
| egg/jest.config.mjs | Mirrors root Jest transform change for egg/. |
Files not reviewed (1)
- egg/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| extensionsToTreatAsEsm: [".mts"], | ||
| transform: { | ||
| "^.+\\.m?tsx?$": ["ts-jest", {}], | ||
| "^.+\\.m?tsx?$": ["@swc/jest"], |
There was a problem hiding this comment.
@swc/jest defaults to emitting CommonJS. Since this repo is ESM (package.json has type: "module") and Jest treats .mts as ESM (extensionsToTreatAsEsm: [".mts"]), transforming atsds/index.mts (which uses top-level await) to CommonJS is likely to break test execution. Configure the SWC transform to emit ESM (module type es6/esnext) and target a runtime that supports top-level await (e.g., es2022/esnext), either by passing options to the transform entry or by adding a project .swcrc used by Jest.
| "^.+\\.m?tsx?$": ["@swc/jest"], | |
| "^.+\\.m?tsx?$": [ | |
| "@swc/jest", | |
| { | |
| module: { | |
| type: "es6", | |
| }, | |
| jsc: { | |
| target: "es2022", | |
| }, | |
| }, | |
| ], |
| extensionsToTreatAsEsm: [".mts"], | ||
| transform: { | ||
| "^.+\\.m?tsx?$": ["ts-jest", {}], | ||
| "^.+\\.m?tsx?$": ["@swc/jest"], |
There was a problem hiding this comment.
Same concern as root config: with type: "module" and .mts treated as ESM, @swc/jest needs to be configured to output ESM (and a target that supports top-level await) or Jest may fail when importing .mts sources during tests.
| "^.+\\.m?tsx?$": ["@swc/jest"], | |
| "^.+\\.m?tsx?$": ["@swc/jest", { | |
| jsc: { | |
| parser: { | |
| syntax: "typescript", | |
| tsx: true, | |
| }, | |
| target: "es2022", | |
| }, | |
| module: { | |
| type: "es6", | |
| }, | |
| }], |
hzhangxyz
left a comment
There was a problem hiding this comment.
github action 报错了:
cross-env NODE_OPTIONS='$NODE_OPTIONS --experimental-vm-modules' jest --config=jest.config.mjs
(node:4308) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
FAIL tests/test_chain.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
(node:4309) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
FAIL tests/test_rule.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
(node:4310) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
FAIL tests/test_term.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
FAIL tests/test_search.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
FAIL tests/test_variable.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
FAIL tests/test_list.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
FAIL tests/test_item.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
FAIL tests/test_string.mjs
● Test suite failed to run
x Expected ',', got '*'
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
,-[/home/runner/work/ds/ds/atsds/index.mts:7:1]
4 | */
5 |
6 | import create_ds from "./ds.mjs";
7 | import type * as dst from "./ds.d.mts";
: ^
8 |
9 | const ds: dst.EmbindModule = await create_ds();
`----
Caused by:
Syntax Error
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 8 failed, 8 total
Tests: 0 total
Snapshots: 0 total
Time: 0.697 s
Ran all test suites.
ERROR: "test" exited with 1.
Error: Process completed with exit code 1.
…rget Agent-Logs-Url: https://github.com/USTC-KnowledgeComputingLab/ds/sessions/83f8342a-8eae-44c2-affd-0431f0cea60e Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
Fixed in b522d17. Both
|
jest.config.mjs: replacets-jesttransform with@swc/jestegg/jest.config.mjs: replacets-jesttransform with@swc/jestpackage.json: removets-jest, add@swc/coreand@swc/jestdevDependenciesegg/package.json: removets-jest, add@swc/coreand@swc/jestdevDependenciesnpm installin root andegg/to updatepackage-lock.jsonjsc.parser.syntax: "typescript",jsc.target: "es2022",module.type: "es6") to both jest configs so@swc/jestuses the TypeScript parser and emits ESMbnf/jest.config.mjshas no ts transform, no changes needed there