rusackas opened a new pull request, #45595:
URL: https://github.com/apache/superset/pull/45595

   ### SUMMARY
   Webpack moved to SWC in #35946, but Jest still ran every file through Babel. 
This swaps the Jest transform to `@swc/jest`, with options mirroring 
`babel.config.js` for the test environment (automatic JSX runtime via 
`@emotion/react`, emotion labels on so css-in-js snapshots keep their class 
names, `jest.mock` hoisting, loose class output).
   
   #44210 noted `@swc/jest` wasn't a drop-in because `jest.spyOn` on module 
exports breaks. The reason is that SWC emits exports as lazy, non-configurable 
getters, and reads an export that hasn't initialised yet as a ReferenceError, 
while Babel emitted plain properties pre-set to `undefined`. The suite leans on 
both Babel behaviours in a few hundred places (`jest.spyOn(module, 'name')`, 
and spreading `jest.requireActual()` of a module that's mid-evaluation in an 
import cycle). Rather than rewrite all of those, 
`spec/helpers/swcJestTransformer.js` wraps `@swc/jest` and post-processes its 
output to mark the export getters `configurable` and make an uninitialised 
export read as `undefined`, which is exactly what Babel did. The maintained 
plugin for this (`@swc-contrib/mut-cjs-exports`) rewrites exports eagerly 
instead and breaks the chart registry's import cycle, so it wasn't an option.
   
   Four tests still needed edits: `Login.test.tsx` and `apiResources.test.ts` 
had mock factories referencing a test-local constant that 
`babel-plugin-jest-hoist` used to hoist for them, `exploreUtils.test.tsx` used 
`jest.replaceProperty` on what is now an accessor, and 
`dashboardFilters.test.ts` assigned straight to a module export.
   
   Measured on the 46 SqlLab suites (475 tests) with 2 workers, cold cache then 
warm:
   
   | transform | cold | warm |
   |---|---|---|
   | babel-jest | 65 s | 32 s |
   | @swc/jest | 39 s | 30 s |
   
   So the win is on cold runs (CI shards, fresh worktrees, anything after a 
dependency change), where transpiling was about half the wall time. Warm runs 
are unchanged since test execution dominates there.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A
   
   ### TESTING INSTRUCTIONS
   CI's sharded Jest job is the real test. Locally, `cd superset-frontend && 
npm run test -- src/SqlLab` should pass and finish noticeably faster on a cold 
cache (`npx jest --clearCache` first).
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to