Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: @oxc/jest package #3886

Open
4 tasks
DonIsaac opened this issue Jun 24, 2024 · 4 comments
Open
4 tasks

proposal: @oxc/jest package #3886

DonIsaac opened this issue Jun 24, 2024 · 4 comments
Labels
A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request C-investigation Category - it represents an investigation. Further steps may change/add C-label(s)

Comments

@DonIsaac
Copy link
Collaborator

The Jest testing framework supports transforming code via transform plugins, such as babel-jest, ts-jest, and @swc/jest. It would be a large quality-of-life improvement to use oxc to transform files instead of any of the above packages. The transformer is progressing quite well, and making it usable in Jest could help with the adoption of oxc in general.

Unfortunately, Jest only ships with experimental support for ESM, so transpilation to CJS is a must-have for this to work properly. I took a crack at this about two weeks ago. Within about 2 hours I got about 80% of the way there, with this missing plugin being the only remaining major blocker.

Goals

  • Typescript/ESM transpilation into CJS
  • Should support transpilation to the most recent Node LTS version
  • Should work out-of-the-box, using fields from package.json, tsconfig.json, .babelrc, etc to configure transpilation correctly

Tasks

  • feat: Expose JS bindings for oxc_transform as an NPM package, similar to @oxc/parser
  • feat(transform): support @babel/plugin-transform-modules-commonjs plugin
  • feat: add @oxc/jest NPM package
  • docs: add setup and usage instructions for @oxc/jest to the website.

Considerations

  • The SWC project has @swc/jest in a separate git repo from their core package. Should we do the same thing?
  • Below are what I see as the major pitfalls of @swc/jest that prevent widespread adoption:
    1. @swc/jest unconditionally hoists package imports, which breaks module mocking. This behavior is undocumented, and attempts to fix it by setting the appropriate config property fail as the package always overrides this user-provided value.
    2. .swcrc does not appear to be respected; I've only ever gotten configuration to work by passing a config option explicitly.
    3. @swc/jest does not export type definitions for its config, and the various settings are completely undocumented
    4. External source maps do not work correctly, only inlined ones do. This messes up debugging and code coverage.
@DonIsaac DonIsaac added C-enhancement Category - New feature or request C-investigation Category - it represents an investigation. Further steps may change/add C-label(s) A-transformer Area - Transformer / Transpiler labels Jun 24, 2024
@Boshen
Copy link
Member

Boshen commented Jun 24, 2024

My only concern is the maintenance cost, the core team will not have the time to maintain this :-(

I'm fine with shipping all the puzzles pieces have a separate repo that glues things together with its own release pipeline.

@DonIsaac
Copy link
Collaborator Author

DonIsaac commented Jun 24, 2024

My only concern is the maintenance cost, the core team will not have the time to maintain this :-(

I'm fine with shipping all the puzzles pieces have a separate repo that glues things together with its own release pipeline.

Once transformation is exposed as an npm package, creating a jest plugin package is relatively trivial. @swc/jest is one file and about 200 lines of code. I'd be happy to maintain it myself. Would you be willing to create a git repo for it within oxc-project and give me the permissions needed to maintain it, or should I create it myself?

@Boshen
Copy link
Member

Boshen commented Jun 24, 2024

should I create it myself

Yes please, ping me if you don't have all the permissions.

@DonIsaac
Copy link
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request C-investigation Category - it represents an investigation. Further steps may change/add C-label(s)
Projects
None yet
Development

No branches or pull requests

2 participants