-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
chore: add typechecks for tests of expect-utils
and jest-circus
#13387
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
chore: add typechecks for tests of expect-utils
and jest-circus
#13387
Conversation
@@ -5,7 +5,7 @@ | |||
* LICENSE file in the root directory of this source tree. | |||
*/ | |||
|
|||
import {Circus} from '@jest/types'; | |||
import type {Circus} from '@jest/types'; |
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.
TS caught this. Good. This means that __mocks__
directory is also covered.
@@ -46,16 +46,19 @@ describe('isError', () => { | |||
}); | |||
|
|||
it('should detect errors from another context', () => { | |||
testErrorFromDifferentContext(win => new win.Error()); | |||
testErrorFromDifferentContext( | |||
win => new (win as typeof globalThis).Error(), |
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.
Error
does not exist on type Window
, but all works with typeof globalThis
. Is fine? Or?
@@ -3,5 +3,6 @@ | |||
"compilerOptions": { | |||
"rootDir": "../" | |||
}, | |||
"include": ["../**/*"] | |||
"include": ["../**/*"], | |||
"references": [{"path": "../../../jest-expect"}] |
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.
Needed to include this declaration:
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.
Shouldn't types be built before type testing tests? I.e., no need for a reference?
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.
In this case tsc
needs the reference for augmentation. The packages/jest-circus/tsconfig.json
has this reference, but the packages/jest-circus/src/__tests__/tscongo.json
is extending the root config. That’s why the reference is missing.
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.
Reference is only so the build is in the correct order right? I don't understand why the test builds needs a specific order
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 also thought so, but typecheck was not passing. Just removed references
and now it is passing. Not sure why? ;D Let’s see what CI thinks.
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.
See the error in CI. With references it goes away. I did not know that, just guessed that reference might work. Adding a .d.ts
also works, but reference seemed to be cleaner.
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.
👍
@@ -3,5 +3,6 @@ | |||
"compilerOptions": { | |||
"rootDir": "../" | |||
}, | |||
"include": ["../**/*"] | |||
"include": ["../**/*"], | |||
"references": [{"path": "../../"}] |
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.
To typecheck test files, tsc
runs with -b
flag. Also it gets files in __tests__
and src
directories still in TypeScript, not the compiled ones from build
. It has to build them (in memory). Logically src
has to be build first, so pointing references to packages/jest-circus/tsconfig.json
makes sense.
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.
this makes more sense!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Fixed types and added typechecks for tests of
expect-utils
andjest-circus
packages.Test plan
Green CI.