Commit d60b3eb
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.5 files changed
Lines changed: 264 additions & 53 deletions
File tree
- packages/pluggable-widgets-tools
- test-config
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
9 | 18 | | |
10 | 19 | | |
11 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
Lines changed: 9 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | | - | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
| |||
0 commit comments