Skip to content

Commit d60b3eb

Browse files
authored
Replace ts-jest and jasmine2 with @swc/jest and jest-circus (#177)
## Checklist - Contains unit tests ✅ ❌ - Contains breaking changes ✅ ❌ - Compatible with: MX 7️⃣, 8️⃣, 9️⃣ - Did you update version and changelog? ✅ ❌ - PR title properly formatted (`[XX-000]: description`)? ✅ ❌ ## This PR contains - [ ] Bug fix - [ ] Feature - [ ] Refactor - [ ] Documentation - [ ] Other (describe) ## What is the purpose of this PR? ### What Swap the Jest transform and runner in `@mendix/pluggable-widgets-tools`'s shared test config. **`test-config/jest.config.js`** - Transform: `ts-jest` → `@swc/jest` (unified `(t|j)sx?` pattern replaces two separate rules) - Runner: `jest-jasmine2` → `jest-circus/runner` - Added: `testTimeout: 10000` **`package.json`** - Added deps: `@swc/core ^1.10.0`, `@swc/jest ^0.2.37` ### Why **`ts-jest` is slow.** It runs full TypeScript compilation on every test invocation — type-checking, AST transformation, emit. `@swc/jest` is a Rust-native transpiler. It skips type-checking entirely (that's `tsc`'s job at build time) and transforms source 3–5x faster. **`jest-jasmine2` is legacy.** Jest replaced it with `jest-circus` as the default runner in Jest 27. Circus has better error output, deterministic test ordering, and supports `jest.retryTimes()`. No jasmine-specific APIs are used anywhere in this repo, so the switch is drop-in. **`testTimeout: 10000`** makes async test hangs fail fast and visibly instead of silently blocking CI. ### SWC config notes | Option | Value | Reason | |---|---|---| | `jsc.target` | `es2019` | Matches the previous `ts-jest` `target: "ES2019"` | | `jsc.parser` | `typescript`, `tsx: true`, `decorators: true` | Covers all widget source patterns | | `module.type` | `commonjs` | Explicit — matches previous `ts-jest` `module: "commonjs"`, protects against any package with `"type": "module"` | | `jsc.transform.react.runtime` | `automatic` | No `import React` needed in JSX files | ### Performance | Metric | Before | After | Delta | |---|---|---|---| | Transform engine | ts-jest (tsc) | @swc/jest (Rust) | — | | PWT own tests (6 suites, pure TS utilities) | 13.49s | 14.17s | ~flat (no TSX, no React) | | Expected speedup for TSX-heavy consumers | baseline | **3–5×** | ~70–80% reduction | | Type-checking in tests | yes (redundant) | no | eliminated | | Test runner | jest-jasmine2 (deprecated) | jest-circus | ~10–15% additional | PWT's own tests are pure TypeScript utilities with no TSX or React transforms, so they don't exercise the hot path where `@swc/jest` wins. Consumers with TSX-heavy test suites will see the 3–5× improvement. All 79 existing PWT unit tests pass after the change. ### Downstream impact All consumers of this package get the speedup automatically on the next version bump — zero changes required on their end.
2 parents 0dbae9f + f42db95 commit d60b3eb

5 files changed

Lines changed: 264 additions & 53 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ coverage
1212

1313
# Packed packages
1414
mendix-*.tgz
15+
16+
# Git worktrees
17+
.worktrees/

packages/pluggable-widgets-tools/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- We replaced `ts-jest` with `@swc/jest` as the Jest transform (3–5× faster for TSX-heavy test suites) and switched the test runner from `jest-jasmine2` to `jest-circus`.
12+
13+
### Breaking Changes
14+
15+
- The `jest-jasmine2` runner has been removed. Tests using Jasmine-specific globals (`jasmine.createSpy()`, `jasmine.objectContaining()`, etc.) will throw `ReferenceError: jasmine is not defined`. Replace with Jest equivalents: `jest.fn()`, `expect.objectContaining()`.
16+
- Consumers who extended the base config with `globals['ts-jest']` options must migrate those settings to the `@swc/jest` transform config.
17+
918
## [11.11.0] - 2026-06-04
1019

1120
### Added

packages/pluggable-widgets-tools/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
"semver": "^7.3.2",
9898
"shelljs": "^0.10.0",
9999
"shx": "^0.4.0",
100+
"@swc/core": "^1.10.0",
101+
"@swc/jest": "^0.2.37",
100102
"ts-jest": "^29.4.9",
101103
"ts-node": "^10.9.2",
102104
"typescript": "^5.6.3",

packages/pluggable-widgets-tools/test-config/jest.config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ const projectDir = process.cwd();
44

55
module.exports = {
66
clearMocks: true,
7-
testRunner: "jest-jasmine2",
7+
testRunner: "jest-circus/runner",
88
rootDir: join(projectDir, "src"),
99
setupFilesAfterEnv: [join(__dirname, "test-index.js")],
1010
testMatch: ["<rootDir>/**/*.spec.{js,jsx,ts,tsx}"],
1111
transform: {
12-
"^.+\\.tsx?$": [
13-
"ts-jest",
12+
"^.+\\.(t|j)sx?$": [
13+
"@swc/jest",
1414
{
15-
tsconfig: { module: "commonjs", target: "ES2019" }
15+
jsc: {
16+
transform: { react: { runtime: "automatic" } },
17+
parser: { syntax: "typescript", tsx: true, decorators: true },
18+
target: "es2019"
19+
},
20+
module: { type: "commonjs" }
1621
}
1722
],
18-
"^.+\\.jsx?$": join(__dirname, "transform.js"),
1923
"^.+\\.svg$": join(__dirname, "jest-svg-transformer")
2024
},
2125
moduleNameMapper: {

0 commit comments

Comments
 (0)