-
Notifications
You must be signed in to change notification settings - Fork 26
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
Spike/scripts jest tests #2376
Spike/scripts jest tests #2376
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from the PR description, and I can confirm that the tests run as expected for me.

I can't speak to the details of the code changes (or the extent of work that ended up being required!), but happy to merge.
Not sure of the best way to track the future TODOs. I've broken out one into #2378 and assigned myself as I think it'd be sensible to acquaint myself with the changes.
Thanks @jfmcquade Thanks for adding the follow-up issue, for the remaining tasks: Consider refactor app tests to use Jest Start testing support for Node 22 Update docs, check nvmrc and node switching hooks |
PR Checklist
Description
The core repo has quite specific requirement for Node >=18 and <=20.7.0 due to issues with tests outlined in #2185 and #2372.
Attempts had been made with #2186 to fix the implementation of mock-fs, however getting any solution working within the current testing infrastructure was proving difficult.
This PR instead aims to replace the core testing infrastructure (based on Jasmine) with Jest, which in turn has better support for mocking the methods that need replacement.
Main Changes
Review Notes
The changes are pretty hard to follow as there's a mix of find/replace and bits of refactoring. Ultimately the main thing to check is that the test suite still runs and passes locally.
yarn workspace scripts test
There shouldn't really be any scope for knock-ons to the main scripts themselves or any apps
Dev Notes
Jest was selected as a successor to Jasmine as ultimately that is the direction the angular team say that they are headed in (https://blog.angular.dev/moving-angular-cli-to-jest-and-web-test-runner-ef85ef69ceca) and also significantly the most popular tools used nowadays (Jasmine is no longer even tracked in stateofjs surveys, and gets mentioned by 16% of respondents in the additional section)
Not a huge amount should be different from a test-authoring perspective, focused tests are now defined by
it.only(...)
instead offit(...)
but most spies and mocks have similar syntax. It is also possible to only run tests on a single file by name, e.g.yarn workspace scripts test -t base.spec.ts
(comments have been added to a handful of files to indicate).One key difference from a developer perspective is that by default jest runs tests in parallel. This had a number of breaking changes for a number of our tests that read/write and clear local test file folders and log files. I started to refactor tests to work around this (using virtual file systems where possible, in-memory logging options and various other fixes), although eventually realised you could pass a
runInBand
flag to jest to run sequentially rather than in parallel. Interestingly enough this also speeds up the test suite by around 50% (a lot of duplicate cache data gets moved across parallel processes), so I think it's fine to just keep this way.As for virtual filesystems, mock-fs has been replaced by memfs. The syntax is slightly different so see the updated examples in the code
Future TODOs
.nvmrc
and yarn/husky hooks to see if any auto-switching enabled Chore: set default node version 20 #2385Git Issues
Closes #2186
Screenshots/Videos
Test suites passing with Jest Runner on Node 20.17.0
