-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest-runner): improve typings by exposing
TestRunner
abstract …
…classes (#12646)
- Loading branch information
1 parent
a93def0
commit 420ba45
Showing
11 changed files
with
196 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
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 { | ||
OnTestFailure, | ||
OnTestStart, | ||
OnTestSuccess, | ||
TestRunnerContext, | ||
TestRunnerOptions, | ||
TestWatcher, | ||
UnsubscribeFn, | ||
} from 'jest-runner'; | ||
|
||
const globalConfig = {} as Config.GlobalConfig; | ||
const runnerContext = {} as TestRunnerContext; | ||
|
||
// CallbackRunner | ||
|
||
class CallbackRunner extends CallbackTestRunner { | ||
async runTests( | ||
tests: Array<Test>, | ||
watcher: TestWatcher, | ||
onStart: OnTestStart, | ||
onResult: OnTestSuccess, | ||
onFailure: OnTestFailure, | ||
options: TestRunnerOptions, | ||
): Promise<void> { | ||
expectType<Config.GlobalConfig>(this._globalConfig); | ||
expectType<TestRunnerContext>(this._context); | ||
|
||
return; | ||
} | ||
} | ||
|
||
const callbackRunner = new CallbackRunner(globalConfig, runnerContext); | ||
|
||
expectType<boolean | undefined>(callbackRunner.isSerial); | ||
expectType<false>(callbackRunner.supportsEventEmitters); | ||
|
||
// EmittingRunner | ||
|
||
class EmittingRunner extends EmittingTestRunner { | ||
async runTests( | ||
tests: Array<Test>, | ||
watcher: TestWatcher, | ||
options: TestRunnerOptions, | ||
): Promise<void> { | ||
expectType<Config.GlobalConfig>(this._globalConfig); | ||
expectType<TestRunnerContext>(this._context); | ||
|
||
return; | ||
} | ||
|
||
on<Name extends keyof TestEvents>( | ||
eventName: string, | ||
listener: (eventData: TestEvents[Name]) => void | Promise<void>, | ||
): UnsubscribeFn { | ||
return () => {}; | ||
} | ||
} | ||
|
||
const emittingRunner = new EmittingRunner(globalConfig, runnerContext); | ||
|
||
expectType<boolean | undefined>(emittingRunner.isSerial); | ||
expectType<true>(emittingRunner.supportsEventEmitters); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"skipLibCheck": true, | ||
|
||
"types": [] | ||
}, | ||
"include": ["./**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.