Skip to content

Replace ts-jest with @swc/jest for Jest TypeScript tests - #123

Merged
hzhangxyz merged 2 commits into
mainfrom
copilot/replace-ts-jest-with-swc-jest
Apr 6, 2026
Merged

Replace ts-jest with @swc/jest for Jest TypeScript tests#123
hzhangxyz merged 2 commits into
mainfrom
copilot/replace-ts-jest-with-swc-jest

Conversation

Copilot AI commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

TypeScript ^6.0.2 raises TS5107 (moduleResolution=node10 deprecated) which breaks ts-jest. Replacing ts-jest with @swc/jest sidesteps the issue entirely — SWC transpiles without invoking the TypeScript compiler.

Changes

  • package.json: Remove ts-jest, add @swc/core and @swc/jest as devDependencies
  • jest.config.js: Swap ts-jest transform for @swc/jest with minimal config (no custom options needed)
// Before
transform: {
    "^.+\\.tsx?$": ["ts-jest", { useESM: true, tsconfig: "<rootDir>/tsconfig.json" }],
}

// After
transform: {
    "^.+\\.tsx?$": ["@swc/jest"],
}

ESM mode is preserved via the existing extensionsToTreatAsEsm: [".ts"] and --experimental-vm-modules in the test script. The explicit tsconfig and useESM options 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:

  1. Prefer default configuration: if @swc/jest works without custom options, keep transform config minimal.
  2. If configuration is necessary, prefer modern/latest targets (e.g., esnext) where applicable.
  3. Update package.json to remove ts-jest and add @swc/jest and @swc/core as devDependencies.
  4. Update jest.config.js accordingly.
  5. Update package-lock.json to reflect dependency changes.
  6. Ensure Jest still runs in ESM mode (project uses package.json type=module and tests are .ts ESM).
  7. CI matrix runs Node 20/22/24; ensure compatibility.

Relevant existing files at head SHA ab72d76:

  • package.json: has devDependencies jest ^30.3.0, ts-jest ^29.4.9, typescript ^6.0.2.
  • jest.config.js uses ts-jest transform with useESM: true and tsconfig: /tsconfig.json.
  • tsconfig.json has moduleResolution bundler.
  • workflow .github/workflows/jest.yml runs npm ci then npm run all.

Acceptance:

  • Jest tests compile and run without TS5107 and without adding ignoreDeprecations.
  • Keep jest config as minimal as possible; only add explicit SWC options if tests fail without them.

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, and 24 (.github/workflows/jest.yml, ref ab72d762e2aa66e22af9482169ae5a9a3f792a79), and it affects every test file because they all go through the same ts-jest transform (jest.config.js, same ref).

Fix (recommended): silence the deprecation error in tsconfig.json

Add ignoreDeprecations to your compilerOptions. 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:

  • The workflow is running a newer TypeScript version (or ts-jest/typescript combo) that now treats this deprecation as an error unless you explicitly opt in to ignoring TS 6.x deprecations.
  • Adding "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 in package.json (not shown in the retrieved files), e.g. set typescript to a stable 5.x/6.x version and reinstall lockfile.

Notes

  • Your current tsconfig.json already sets "moduleResolution": "bundler" (not node10), so this deprecation is likely coming from a dependency default or a secondary config used by the test toolchain. The ignoreDeprecations setting is designed for exactly this situation and will make CI green again without changing runtime behavior.

After applying the tsconfig.json change 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(ref ab72d762...)里,moduleResolution 是:

  • "moduleResolution": "bundler"

所以 不是你这个 tsconfig.json 直接写了 node10

触发 moduleResolution=node10 的来源通常有 3 类(按常见程度排序):

  1. **`ts-je...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Replace ts-jest with @swc/jest for Jest TypeScript tests Replace ts-jest with @swc/jest for Jest TypeScript tests Apr 6, 2026
Copilot AI requested a review from hzhangxyz April 6, 2026 12:01
@hzhangxyz
hzhangxyz marked this pull request as ready for review April 6, 2026 12:24
Copilot AI review requested due to automatic review settings April 6, 2026 12:24
@hzhangxyz
hzhangxyz merged commit afa5416 into main Apr 6, 2026
26 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-jest and added @swc/core + @swc/jest to devDependencies.
  • Updated Jest transform configuration to use @swc/jest.
  • Regenerated package-lock.json to 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.

Comment thread package.json
Comment on lines 40 to 48
"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",

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread package.json
Comment on lines 38 to +42
"@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",

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
"@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",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants