-
Notifications
You must be signed in to change notification settings - Fork 224
Enable/fix test typing in multiple packages #2016
Conversation
@@ -0,0 +1,2 @@ | |||
// Import jest matchers for the purposes of type checking. sewing-kit performs a similar setup before running jest tests. | |||
import '@shopify/react-testing/matchers'; |
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.
Would include work instead? https://www.typescriptlang.org/tsconfig#include
I don't have a problem with this solution.
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.
I poked around with this on friday afternoon, got nowhere conclusive yet, but I've got some alternative ideas that I didn't have time to try.
On the up side, this works.
On the down side it seems to work because there's any old file in each project and that kicks TS enough to realize it needs to apply the global augments. These files are never included and ran at runtime at any point which means this feels like load-bearing spookyness to me. They might as well be called packages/react-app-bridge-universal-provider/burp.ts.
I'd feel more comfortable with this approach if these specific files were executed at runtime too.
It looks like sewing-kit-next
would ready the files in packages/BLAH/tests/setup/test.ts (matching how tests/setup/test.ts works at the workspace root). If you remove the matchers from the global test setup (tests/setup/test.ts
and apply them on a per-project basis then would mean this runtime-behaviour was important.
Alternatively instead of adding config to each project i wonder if we could repeat the declare global
inside a config/typescript/matchers.d.ts file
and have those files included in the projects that need them (same as the other stuff in the config/typescript directory). I'm tempted to say that repetition of the declare block feels nicer than having to add a file that is never executed at runtime to each package as it has a smaller footprint.
|
Fantastic work, thanks for continuing to poke at this.
Yeah, we could change it so for packages the root is the package folder (
There's probably some cuteness around "only loading what you need for a given package" but my gut-feel is those gains are going to be negligible and not worth the extra complexity compared to doing all the setup once at the workspace level. I think I'm leaning towards the idea that for now we shouldn't need per-package testing config and that it's better that we keep the test config stuff centralised at the workspace level (i.e. what we have now). I reckon let's run with what you've got in ab388b0 - removing the per-package files, and having a I wonder if you can remove the saddle-up matchers and replace the following to trigger the global augments:
|
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.
🎉
Description
Enabled type checking in a batch of react packages. The type errors being caused in these tests were caused because typescript had no visibility on the global jest matchers (
@shopify/react-testing/matchers
) imported by sewing kit viatests/setup/tests.ts
when running tests.This was addressed by adding a single file
src/tests/setup.ts
that imported@shopify/react-testing/matchers
.Note:
tests/setup/tests.ts
could be imported directly by adding atsconfig.json
file totests/
and adding it as a project reference in all relevant packages, but this adds additional complexity with no major benefit.Type of change
Checklist