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

feat(jest): SWC support for jest #308

Closed
wants to merge 1 commit into from
Closed

Conversation

glorat
Copy link
Contributor

@glorat glorat commented Nov 26, 2022

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • New test runner
  • Documentation
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • It's submitted to the dev branch and not the master branch
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix: #xxx[,#xxx], where "xxx" is the issue number)
  • It's been tested on Windows
  • It's been tested on Linux
  • It's been tested on MacOS
  • Any necessary documentation has been added or updated in the docs (for faster update click on "Suggest an edit on GitHub" at bottom of page) or explained in the PR's description.

If adding a new feature, the PR's description includes:

Other information:

Copy link
Member

@IlCallo IlCallo left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, not much time in these weeks
Not sure if the PR is actually ready for review, but I left some comments around

packages/unit-jest/package.json Show resolved Hide resolved
@@ -25,6 +25,10 @@ module.exports = function () {
name: 'TypeScript support',
value: 'typescript',
},
{
name: 'SWC for TypeScript (experimental)',
Copy link
Member

Choose a reason for hiding this comment

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

I'd use "Use SWC instead of ts-jest to transpile TypeScript (experimental, at least 20x faster transpilation, see )"
It's way longer, but provides more context about what SWC project is and why it's useful

// },
// },
transform: {
[`^(${quasarEsModulesPackageNames}).+\\.js$`]: 'babel-jest',
Copy link
Member

Choose a reason for hiding this comment

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

Can we skip using babel-jest altogether and use @swc/jest for Quasar dependencies too? That would be a big plus, as we currently have to transpile Quasar ESM prod build when running Jest tests and Babel is pretty slow in doing that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not familiar with all the quasar build output so not sure what to point to. All I can say at this moment is that after commenting out this line, there is no performance difference (although it does still work)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested on another machine... SWC might be slightly faster here (10%?) but not significant. It's definitely not slower and seems to work so I'll remove the babel-jest on next commit

Copy link
Member

Choose a reason for hiding this comment

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

Perfect

@@ -68,6 +68,14 @@ module.exports = function (api) {
}typescript`,
);

if (api.prompts.options.includes('swc')) {
api.render(`./templates/swc`)
Copy link
Member

Choose a reason for hiding this comment

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

I guess this relies on the fact that ts-jest files are scaffolded first, so we're overwriting the scaffolded ones here
It's ok to rely on this kind of execution-order assumptions due to it being experimental, but I'd make it explicit with a comment

@@ -284,6 +284,10 @@ This AE ships with project-level type-checking disabled by default since it incr

Project-wide type-checking already takes place during development and into your IDE, so you won't usually need this during tests anyway.

##### SWC support

Experimental support has been added for [swc/jest](https://swc.rs/docs/usage/jest), which is a drop-in Rust replacement for ts-jest and should make your TypeScript Jest tests run faster. To install it, choose the relevant option when prompted on installation, ensuring also to choose typescript.
Copy link
Member

Choose a reason for hiding this comment

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

Is the SWC option meant to only pop out when you select TS support?
I think we can do so by adding a new question and making the SWC one conditionally bound to the TS one
Is it possible to use SWC for both JS and TS with the same configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted it to only popup for typescript but the prompts API doesn't seem to support such an optional question. So currently it does nothing if typescript isn't also selected.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC Quasar uses Inquirer to process these prompts
You should be able to define a "when" option to control when to show a question

If you aren't able to do so, I'll take a look when you set the PR as ready to review

@glorat
Copy link
Contributor Author

glorat commented Dec 5, 2022

Some testing on a couple of projects I run. To test performance, I am using npx jest --no-cache and running a few times to get a median result.

On the smaller project on a fast machine

  • ts-jest - 5.6 seconds
  • swc/jest - 2.1 seconds

On a large project including component testing on a slow machine

  • test-jest - 47 seconds
  • swc/jest - 17 seconds

On same project without any component testing on a slow machine

  • ts-jest - 12 seconds
  • swc/jest - 9 seconds

@IlCallo
Copy link
Member

IlCallo commented Feb 14, 2023

Hey there!
I see this is still hanging here in draft mode, are you still interested in contributing?

@glorat
Copy link
Contributor Author

glorat commented Jun 23, 2023

Hey there! I see this is still hanging here in draft mode, are you still interested in contributing?

Sorry for radio silence... what's happened is that my projects have switched to vite and vitest so this is left hanging. For anyone still on webpack framework wanting to use SWC, this change is still good. But I don't think it is worth the effort anymore to make this a real plug-in enhancement. Instead, might simply be better to leave documentation on how people could switch to SWC.

@IlCallo
Copy link
Member

IlCallo commented Jun 23, 2023

Ok, no problem, I'll close the PR in that case
Thanks for clarifying!

@IlCallo IlCallo closed this Jun 23, 2023
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.

2 participants