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

(jest) improves performance and mem use reduction; adds compatibility with 3rd party tools; fwds all args to jest command #4096

Merged
merged 31 commits into from
Feb 2, 2022

Conversation

dac09
Copy link
Contributor

@dac09 dac09 commented Jan 10, 2022

Closes #2708
Closes #4017
Closes #3413
Closes #3419

What does this do?

Changes how jest is configured in the following ways:

  1. adds a root jest.config.js to Redwood projects. This is required for other tools (and the jest cli itself) to know what config to load. (See examples section)
  2. removes the need for packages/testing/config/jest/jest.config.js, as I've moved this code into the presets i.e. packages/testing/config/jest/api/jest-preset.js and packages/testing/config/jest/web/jest-preset.js. We don't need to pass this hidden config file anymore
  3. in the web/jest.config.js and api/jest.config.js - we now use presets, instead of importing the module. Why? This seems to work better with tooling e.g. Wallaby (see examples)
  4. Moves logic for prisma reset from the cli, to jest-preset. This ensures the scenarios work even without the redwood cli.
  5. Keeps backward compatibility - i.e. if you don't use the new web/jest.config.js, ./jest.config.js and api/jest.config.js in your project, it will still work as before
  6. Include's @callingmedic911 fix for coverage folder in Fix: Jest not using the project root config #4059

Examples & Why things are done this way

Img

@dac09 dac09 self-assigned this Jan 10, 2022
@dac09 dac09 changed the title Setup backwards compatible settings with jest-preset Update jest config for better tooling support Jan 10, 2022
@dac09 dac09 added the release:fix This PR is a fix label Jan 11, 2022
dac09 added 2 commits January 11, 2022 15:19
…d into fix/standardize-jest-config

* 'fix/standardize-jest-config' of github.com:dac09/redwood:
  add node-fetch renovate blocklist
  Update dependency msw to v0.36.4 (redwoodjs#4116)
  Update dependency @clerk/types to v1.21.0 (redwoodjs#4115)
  Update dependency @envelop/testing to v3.0.1 (redwoodjs#4113)
  Update dependency qs to v6.10.3 (redwoodjs#4111)
  Update dependency @envelop/testing to v3 (redwoodjs#4078)
  Update typescript-eslint monorepo to v5.9.1 (redwoodjs#4101)
  Update dependency cypress to v9.2.1 (redwoodjs#4110)
  Update dependency fast-glob to v3.2.9 (redwoodjs#4075)
  Update storybook monorepo to v6.4.10 (redwoodjs#4091)
  Update dependency @apollo/client to v3.5.7 (redwoodjs#4097)
  add timeout (redwoodjs#4107)
  Pin dependency webpack-dev-server to 4.7.2 (redwoodjs#4093)
  Update dependency @envelop/core to v1.7.1 (redwoodjs#4092)
  Add missing type for `only` in scenario (redwoodjs#4083)
@callingmedic911 callingmedic911 self-requested a review January 13, 2022 04:15
@dac09 dac09 requested a review from jtoar January 14, 2022 12:19
@dac09
Copy link
Contributor Author

dac09 commented Jan 14, 2022

@jtoar can I request you take a look at this too please? We have a few jest PRs in progress, I think this one should go last

Copy link
Member

@callingmedic911 callingmedic911 left a comment

Choose a reason for hiding this comment

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

I also checked out locally and tested this. Looks good! I left a few minor subjective suggestions. We now just need to rebase on main to include parallel execution change.

Lastly, do you think I should close #4059?

Over to you and @jtoar for the final call. :)

dac09 added 5 commits January 17, 2022 11:31
…ize-jest-config

* 'main' of github.com:redwoodjs/redwood: (32 commits)
  Update dependency eslint to v8.7.0 (redwoodjs#4168)
  remove projects beta automation (redwoodjs#4171)
  Update dependency core-js to v3.20.3 (redwoodjs#4162)
  Don't mask GraphQL errors when you're in the dev environment (redwoodjs#4166)
  Update storybook monorepo to v6.4.13 (redwoodjs#4160)
  Fix: Run web tests in parallel (redwoodjs#4024)
  Update Issue and PR templates with v1-rc status (redwoodjs#4155)
  Update dependency fast-glob to v3.2.11 (redwoodjs#4158)
  Update dependency @auth0/auth0-spa-js to v1.19.4 (redwoodjs#4153)
  Update dependency react-hook-form to v7.24.0 (redwoodjs#4149)
  Update dependency @clerk/clerk-sdk-node to v2.6.1 (redwoodjs#4151)
  Update prisma monorepo to v3.8.1 (redwoodjs#4152)
  Update e2e.yaml
  Update dependency firebase to v9.6.3 (redwoodjs#4148)
  chore(setup-deploy): refactor setup deploy (redwoodjs#4065)
  Update dependency mini-css-extract-plugin to v2.4.7 (redwoodjs#4142)
  test project install autoprefixer@^9.8.8 (redwoodjs#4143)
  Update dependency @graphql-codegen/typescript-react-apollo to v3.2.4 (redwoodjs#4137)
  Render all MetaTag tags within a `<Head>` element (redwoodjs#4128)
  fix: running tests with mysql datasource (redwoodjs#4084)
  ...
…d into fix/standardize-jest-config

* 'fix/standardize-jest-config' of github.com:dac09/redwood:
  Refactor `rw type-check` (redwoodjs#4086)
@dac09
Copy link
Contributor Author

dac09 commented Jan 17, 2022

Note
Due to the other changes we've made recently to jest-config, Wallaby doesn't work out of the box for the api side. To get it working you need to add an extra line to api/jest.config.js.

const config = {
  rootDir: '../',
  preset: '@redwoodjs/testing/config/jest/api',
}
+ if (process.env.DEBUG?.includes('wallaby')) config.runner = 'jest-runner';
module.exports = config

dac09 added 3 commits January 17, 2022 14:36
…d into fix/standardize-jest-config

* 'fix/standardize-jest-config' of github.com:dac09/redwood:
  Update dependency mini-css-extract-plugin to v2.5.0 (redwoodjs#4156)
  Update dependency @types/node to v16.11.20 (redwoodjs#4172)
@callingmedic911 callingmedic911 linked an issue Jan 18, 2022 that may be closed by this pull request
dac09 added 2 commits February 1, 2022 22:29
…ize-jest-config

* 'main' of github.com:redwoodjs/redwood: (46 commits)
  update contributing content (redwoodjs#4325)
  Upgrade yarn to 3.1.1 (redwoodjs#3919)
  Sort package.jsons (redwoodjs#4309)
  Update dependency esbuild to v0.14.16 (redwoodjs#4322)
  Add explanation and docs link in generated tests (redwoodjs#4218)
  Update dependency webpack to v5.68.0 (redwoodjs#4315)
  Update dependency esbuild to v0.14.15 (redwoodjs#4321)
  Update dependency cypress to v9.4.1 (redwoodjs#4319)
  Update dependency @typescript-eslint/parser to v5.10.2 (redwoodjs#4318)
  Pin dependencies (redwoodjs#4317)
  Pull proper keys for Yarn and npm (redwoodjs#4313)
  Add missing deps to @redwoodjs/forms package.json (redwoodjs#4310)
  Update dependency @typescript-eslint/eslint-plugin to v5.10.2 (redwoodjs#4314)
  Tweak release script (redwoodjs#4312)
  Update dependency @graphql-codegen/typescript-operations to v2.2.3 (redwoodjs#4311)
  Update dependency vscode-languageserver-textdocument to v1.0.4 (redwoodjs#4308)
  Update dependency copy-webpack-plugin to v10.2.4 (redwoodjs#4307)
  Update storybook monorepo to v6.4.17 (redwoodjs#4306)
  Update release script (redwoodjs#4305)
  Update dependency msw to v0.36.8 (redwoodjs#4301)
  ...
dac09 added 3 commits February 1, 2022 22:54
…ize-jest-config

* 'main' of github.com:redwoodjs/redwood:
  Update dependency @types/vscode to v1.63.2 (redwoodjs#4332)
  createCell: Give cell results priority over cell props (redwoodjs#4304)
  Update dependency node-notifier to v10.0.1 (redwoodjs#4331)
  Update dependency core-js to v3.21.0 (redwoodjs#4330)
  Update dependency @clerk/clerk-js to v2.12.1 (redwoodjs#4327)
  Update dependency @clerk/types to v1.24.1 (redwoodjs#4328)
  Update dependency supertokens-node to v8.6.0 (redwoodjs#4324)
  Update prisma monorepo to v3.9.0 (redwoodjs#4329)
  Update dependency @types/node to v16.11.22 (redwoodjs#4326)
@dac09 dac09 changed the title Update jest config for better tooling support Standardize jest config, to decouple cli from jest Feb 2, 2022
@dac09
Copy link
Contributor Author

dac09 commented Feb 2, 2022

@thedavidprice gone through the checklist

@dac09 Final checklist I suggest to move this one to merge:

* [x]  Add a section to [redwoodjs.com/docs/testing](https://redwoodjs.com/docs/testing) about Jest Config, including the 3 config files and code for each: explain how it works and why it's need to be compatible with the ecosystem

PR created here: https://github.com/redwoodjs/redwoodjs.com/pull/959

Can you please confirm you're happy with the title of the page? I'll update all the links

  * add commented links to this section of Docs in crwa/template/ (see specific comments for each of the 3 files)

Will need updating

* [x]  Determine what to do about [Running tests with multiple "--coverageReporters" options #3419](https://github.com/redwoodjs/redwood/issues/3419) (if not able to resolve here)

Added fix for this also. Thanks for scope creep 😉 ✌️

* [ ]  Determine when to handle check for config in web/ and api/ ([comment above](https://github.com/redwoodjs/redwood/pull/4096#issuecomment-1024810384))

I want to discuss this further, but also don't think we need this in the PR, its already grown too much in scope I think!

* [x]  Being able to foward all commands to Jest is a big improvement. Can you update the PR title to mention this as well so we call it out better?

Done

* [ ]  I need copy to include in Release Notes
  
  * briefly explaining changes here (the "why") and that they're backwards compatible
  * explain how to upgrade to new config (you're going to add a codemod, aren't you? 😂)

I don't think we need a codemod because its backwards compatible. If you're happy with your jest config, then probably no need to change!

Blurb:
We've improved our jest configuration so that
a) It uses about 40-50% less memory
b) Its easier to use whatever tools you usually use to run your tests, instead of just through the redwood cli. Infact, its pretty vanilla now, so if you wish you can directly run the jest cli from the commandline yarn jest and it'll pick up all the redwood settings! Checkout the forums, if you're looking for how to use redwood's test with your tool of choice.

@orta
Copy link
Contributor

orta commented Feb 2, 2022

Nice, I think this is enough to run wallabyjs on redwood tests, it's my only current codebase which doesn't work with it

Copy link
Contributor Author

dac09 commented Feb 2, 2022

It is! Been my personal mission, also ❤️ wallaby. It does need a little tweak to the config though (see my first comment on this pr)

dac09 added 3 commits February 3, 2022 01:31
…d into fix/standardize-jest-config

* 'fix/standardize-jest-config' of github.com:dac09/redwood:
  Update dependency @types/netlify-identity-widget to v1.9.3 (redwoodjs#4343)
  Update dependency webpack-dev-server to v4.7.4 (redwoodjs#4337)
  Update dependency @clerk/clerk-sdk-node to v2.8.0 (redwoodjs#4336)
  Update dependency esbuild to v0.14.17 (redwoodjs#4333)
@thedavidprice thedavidprice changed the title Standardize jest config, to decouple cli from jest (jest) improves performance and mem use reduction; adds compatibility with 3rd party tools; fwds all args to jest command Feb 2, 2022
@thedavidprice
Copy link
Contributor

Performance

I did a quick mem before and after check and reported it over here in #4208

Confirming Web seems resolved and API is reduced but about 50%. 🚀

@thedavidprice
Copy link
Contributor

So very solid. Huge lift here @dac09 Well done 🚀

I'm working with @dac09 on docs and other next steps. Will get this into forthcoming release.

@thedavidprice thedavidprice merged commit 6116159 into redwoodjs:main Feb 2, 2022
@jtoar jtoar added this to the next-release milestone Feb 2, 2022
@thedavidprice thedavidprice modified the milestones: next-release, v0.44.0 Feb 3, 2022
@dac09 dac09 deleted the fix/standardize-jest-config branch February 23, 2022 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Archived
5 participants