-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: type TestScheduler's testRunners object #9804
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,6 @@ export type WatcherState = { | |
}; | ||
export interface TestWatcher extends EventEmitter { | ||
state: WatcherState; | ||
new ({isWatchMode}: {isWatchMode: boolean}): TestWatcher; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this type was actually wrong. It implies you can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the examples here have constructors? https://www.typescriptlang.org/docs/handbook/interfaces.html#difference-between-the-static-and-instance-sides-of-classes But it seems like we have to separate them out, or something - I might need to read up on it some more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would we correctly type this so TS knows we'll There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something might have changed? This was my script to try it out interface Hey {
new(foo: number): Hey;
woo: number;
}
function testFunction(hey: Hey) {
new hey(123);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes nothing changed. This is consistent with the docs link you sent. Notice they are defining the interface for the constructor itself, not the Clock. interface ClockConstructor {
new (hour: number, minute: number): ClockInterface;
}
interface ClockInterface {
tick(): void;
} We could add a TestWatcherConstructor interface, but that doesn't seem to represent anything public. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's definitely wrong now, and just deleting is an improvement. The docs say something about the static part (like the constructor) needing to be typed separately from the "instance" functions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make it an abstract class? That's what I would do in Java, and maybe correct here as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An interface looks right to me. The TestWatcher constructor is private. Consumers of this type only ever see TestWatcher instances. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation lives here: https://github.com/facebook/jest/blob/c83051789cc60789f2c575374270236e3a428879/packages/jest-core/src/TestWatcher.ts Maybe we should just move that to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. meh, it's using |
||
setState(state: WatcherState): void; | ||
isInterrupted(): boolean; | ||
isWatchMode(): boolean; | ||
|
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.
The
jest-runner
class right now is the source of truth for all test runners. This means it needs to have anisSerial
property for the test scheduler to use it.In the future, I think TestRunner should become an interface implemented by JestTestRunner.
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.
Yeah, sounds good 👍
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 tried and failed to do the interface patch. The runner interface depends on jest-haste-map, which depends on jest/@types. So I can't put it in types. And it needs to be used by jest-runner, which is depended on by @jest/core, so I can't put it in @jest/core. I'm not sure where it should go without creating a cycle. Can I create a new package? How does that work?
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.
Can it be in
jest-runner
? And yeah, a new package is fine if it doesn't fit anywhere else, although lifting some types out (like I've done in #9747 and #9749) to break cycles might be enough.