Replace ts-jest with @swc/jest for Jest TypeScript tests - #123
Conversation
Agent-Logs-Url: https://github.com/USTC-KnowledgeComputingLab/ddss/sessions/5336e751-5af9-455c-9215-2359a8cbdeb6 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 to run Jest TypeScript tests without invoking the TypeScript compiler (avoiding TypeScript/ts-jest incompatibilities such as TS5107-related failures).
Changes:
- Removed
ts-jestand added@swc/core+@swc/jestto devDependencies. - Updated Jest transform configuration to use
@swc/jest. - Regenerated
package-lock.jsonto reflect dependency graph changes.
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| package.json | Switch devDependencies from ts-jest to @swc/jest/@swc/core. |
| jest.config.js | Swap Jest TypeScript transform from ts-jest to @swc/jest. |
| package-lock.json | Lockfile updates reflecting the Jest transformer dependency swap. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "cross-env": "^10.1.0", | ||
| "@swc/core": "^1.15.24", | ||
| "@swc/jest": "^0.2.39", | ||
| "jest": "^30.3.0", | ||
| "npm-run-all": "^4.1.5", | ||
| "rollup": "^4.59.0", | ||
| "ts-jest": "^29.4.6", | ||
| "ts-node": "^10.9.2", | ||
| "tslib": "^2.8.1", | ||
| "typescript": "^5.9.3", |
There was a problem hiding this comment.
The PR description/title reference TypeScript ^6.0.2 / TS5107 breaking ts-jest, but this branch still pins TypeScript to ^5.9.3 (and the removed ts-jest version is ^29.4.6). If this PR is meant to be the fix for the TypeScript 6 upgrade, please also bump typescript to the intended ^6.x here (or update the PR description to match the actual versions/intent).
| "@types/jest": "^30.0.0", | ||
| "@types/node": "^25.5.0", | ||
| "cross-env": "^10.1.0", | ||
| "@swc/core": "^1.15.24", | ||
| "@swc/jest": "^0.2.39", |
There was a problem hiding this comment.
devDependencies appear to be kept in alphabetical order, but the newly added @swc/* entries are inserted after cross-env, which breaks the existing ordering. Please re-sort devDependencies to keep diffs predictable (e.g., group/sort scoped packages together).
| "@types/jest": "^30.0.0", | |
| "@types/node": "^25.5.0", | |
| "cross-env": "^10.1.0", | |
| "@swc/core": "^1.15.24", | |
| "@swc/jest": "^0.2.39", | |
| "@swc/core": "^1.15.24", | |
| "@swc/jest": "^0.2.39", | |
| "@types/jest": "^30.0.0", | |
| "@types/node": "^25.5.0", | |
| "cross-env": "^10.1.0", |
TypeScript ^6.0.2 raises TS5107 (
moduleResolution=node10deprecated) which breaks ts-jest. Replacing ts-jest with @swc/jest sidesteps the issue entirely — SWC transpiles without invoking the TypeScript compiler.Changes
package.json: Removets-jest, add@swc/coreand@swc/jestas devDependenciesjest.config.js: Swap ts-jest transform for@swc/jestwith minimal config (no custom options needed)ESM mode is preserved via the existing
extensionsToTreatAsEsm: [".ts"]and--experimental-vm-modulesin the test script. The explicittsconfiganduseESMoptions are unnecessary with @swc/jest — it handles both by default.Original prompt
Create a PR on repository USTC-KnowledgeComputingLab/ddss to replace ts-jest with @swc/jest for running Jest TypeScript tests.
Context:
Requirements:
Relevant existing files at head SHA ab72d76:
Acceptance:
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.
Assistant: The job is failing before any tests run because TypeScript compilation (via
ts-jest) errors out with:TS5107: Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.This is happening in the Jest workflow matrix on Node
20,22, and24(.github/workflows/jest.yml, refab72d762e2aa66e22af9482169ae5a9a3f792a79), and it affects every test file because they all go through the samets-jesttransform (jest.config.js, same ref).Fix (recommended): silence the deprecation error in
tsconfig.jsonAdd
ignoreDeprecationsto yourcompilerOptions. This is exactly what the error message asks for and is the lowest-risk change.Patch (tsconfig.json):
{ "compilerOptions": { "target": "esnext", "module": "esnext", "moduleResolution": "bundler", + "ignoreDeprecations": "6.0", "allowImportingTsExtensions": true, "strict": true, "esModuleInterop": true, "isolatedModules": true, "skipLibCheck": true }, "include": ["ddss/*"] }Why this works:
"ignoreDeprecations": "6.0"unblocks compilation while keeping your existing settings (including"moduleResolution": "bundler").Alternative (more strict): pin TypeScript to a known-working version
If you prefer not to use
ignoreDeprecations, you can pin TypeScript to a version that doesn’t error on this deprecation (or that matches your existing config expectations). This is done inpackage.json(not shown in the retrieved files), e.g. settypescriptto a stable 5.x/6.x version and reinstall lockfile.Notes
tsconfig.jsonalready sets"moduleResolution": "bundler"(notnode10), so this deprecation is likely coming from a dependency default or a secondary config used by the test toolchain. TheignoreDeprecationssetting is designed for exactly this situation and will make CI green again without changing runtime behavior.After applying the
tsconfig.jsonchange above, the Jest job should proceed to actually executing tests instead of failing at “Test suite failed to run”.User: 新版本的这些东西硬怎么来?我是哪个行为被deprecated了?
Assistant: 你现在遇到的并不是“你代码里某一行写法被 deprecated”,而是 TypeScript 编译选项里某个旧的
moduleResolution模式被标记为 deprecated(node10),并且在你这次 CI 用到的 TypeScript 版本里,这个 deprecation 被提升成了直接报错(TS5107),导致ts-jest编译测试文件时全挂。从日志看,报错点是:
Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0.compilerOption '"ignoreDeprecations": "6.0"'你到底“哪一行”触发了 deprecated?
在你仓库的
tsconfig.json(refab72d762...)里,moduleResolution是:"moduleResolution": "bundler"所以 不是你这个 tsconfig.json 直接写了
node10。触发
moduleResolution=node10的来源通常有 3 类(按常见程度排序):This pull request was created from Copilot chat.