I was looking into improving test coverage to >=95% by all instanbul measures, and felt unhappy about how much the snaps-cli tests diverge from our existing standards. Therefore, I decided to convert them to TypeScript and colocate them with the source files.
I took care to modify the test files as little as possible, but some modifications were unavoidable. The only gratuitous modification I made was to pull out some repeatedly declared mocks into equivalent factory functions.
Comparing coverage results between this branch and main, coverage is identical.
Changes, in detail:
Update jest.config.js per module template
Remove all inline calls to jest.restoreAllMocks, since this is now done globally.
Colocate tests with source files
Delete tests directory
Convert tests to TypeScript
Migrate from CommonJS to ESM import syntax
Add a lot of as any, which we can improve later
Add required dev deps: @types/rimraf and ts-jest
Update .eslintrc.js to match new migrated tests files
Create tsconfig.build.json
This config extends our existing tsconfig.json and is used in yarn build. Its purpose is to exclude all tests files. If we exclude all test files in the base config, they don't get the typeRoots, and tsc becomes very unhappy.
I was looking into improving test coverage to >=95% by all
instanbul
measures, and felt unhappy about how much thesnaps-cli
tests diverge from our existing standards. Therefore, I decided to convert them to TypeScript and colocate them with the source files.I took care to modify the test files as little as possible, but some modifications were unavoidable. The only gratuitous modification I made was to pull out some repeatedly declared mocks into equivalent factory functions.
Comparing coverage results between this branch and
main
, coverage is identical.Changes, in detail:
jest.config.js
per module templatejest.restoreAllMocks
, since this is now done globally.tests
directoryas any
, which we can improve later@types/rimraf
andts-jest
.eslintrc.js
to match new migrated tests filestsconfig.build.json
tsconfig.json
and is used inyarn build
. Its purpose is to exclude all tests files. If we exclude all test files in the base config, they don't get thetypeRoots
, andtsc
becomes very unhappy.Ref: #74