-
-
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
feat(jest-runner): export TestRunner
interface types and reexport types from other packages
#12715
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 |
---|---|---|
|
@@ -6,18 +6,21 @@ | |
*/ | ||
|
||
import {expectType} from 'tsd-lite'; | ||
import type {Test, TestEvents} from '@jest/test-result'; | ||
import type {Config} from '@jest/types'; | ||
import {CallbackTestRunner, EmittingTestRunner} from 'jest-runner'; | ||
import type { | ||
CallbackTestRunnerInterface, | ||
Config, | ||
EmittingTestRunnerInterface, | ||
OnTestFailure, | ||
OnTestStart, | ||
OnTestSuccess, | ||
Test, | ||
TestEvents, | ||
TestRunnerContext, | ||
TestRunnerOptions, | ||
TestWatcher, | ||
UnsubscribeFn, | ||
} from 'jest-runner'; | ||
import type {TestWatcher} from 'jest-watcher'; | ||
|
||
const globalConfig = {} as Config.GlobalConfig; | ||
const runnerContext = {} as TestRunnerContext; | ||
|
@@ -45,6 +48,32 @@ const callbackRunner = new CallbackRunner(globalConfig, runnerContext); | |
expectType<boolean | undefined>(callbackRunner.isSerial); | ||
expectType<false>(callbackRunner.supportsEventEmitters); | ||
|
||
// CallbackTestRunnerInterface | ||
|
||
class CustomCallbackRunner implements CallbackTestRunnerInterface { | ||
readonly #maxConcurrency: number; | ||
readonly #globalConfig: Config.GlobalConfig; | ||
|
||
constructor(globalConfig: Config.GlobalConfig) { | ||
this.#globalConfig = globalConfig; | ||
this.#maxConcurrency = globalConfig.maxWorkers; | ||
} | ||
Comment on lines
+53
to
+60
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. Note that |
||
|
||
async runTests( | ||
tests: Array<Test>, | ||
watcher: TestWatcher, | ||
onStart: OnTestStart, | ||
onResult: OnTestSuccess, | ||
onFailure: OnTestFailure, | ||
options: TestRunnerOptions, | ||
): Promise<void> { | ||
expectType<Config.GlobalConfig>(this.#globalConfig); | ||
expectType<number>(this.#maxConcurrency); | ||
|
||
return; | ||
} | ||
} | ||
|
||
// EmittingRunner | ||
|
||
class EmittingRunner extends EmittingTestRunner { | ||
|
@@ -71,3 +100,34 @@ const emittingRunner = new EmittingRunner(globalConfig, runnerContext); | |
|
||
expectType<boolean | undefined>(emittingRunner.isSerial); | ||
expectType<true>(emittingRunner.supportsEventEmitters); | ||
|
||
// EmittingTestRunnerInterface | ||
|
||
class CustomEmittingRunner implements EmittingTestRunnerInterface { | ||
readonly #maxConcurrency: number; | ||
readonly #globalConfig: Config.GlobalConfig; | ||
readonly supportsEventEmitters = true; | ||
|
||
constructor(globalConfig: Config.GlobalConfig) { | ||
this.#globalConfig = globalConfig; | ||
this.#maxConcurrency = globalConfig.maxWorkers; | ||
} | ||
|
||
async runTests( | ||
tests: Array<Test>, | ||
watcher: TestWatcher, | ||
options: TestRunnerOptions, | ||
): Promise<void> { | ||
expectType<Config.GlobalConfig>(this.#globalConfig); | ||
expectType<number>(this.#maxConcurrency); | ||
|
||
return; | ||
} | ||
|
||
on<Name extends keyof TestEvents>( | ||
eventName: string, | ||
listener: (eventData: TestEvents[Name]) => void | Promise<void>, | ||
): UnsubscribeFn { | ||
return () => {}; | ||
} | ||
} |
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 way better.