forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest-worker): add
JestWorkerFarm
helper type (jestjs#12753)
- Loading branch information
1 parent
4efda33
commit ae58ef7
Showing
15 changed files
with
202 additions
and
52 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
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,80 @@ | ||
/** | ||
* 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 {expectError, expectType} from 'tsd-lite'; | ||
import type {JestWorkerFarm} from 'jest-worker'; | ||
import type * as testWorker from './testWorker'; | ||
|
||
type TestWorker = { | ||
runTest: () => void; | ||
isResult: boolean; | ||
end: () => void; // reserved keys should be excluded from returned type | ||
getStderr: () => string; | ||
getStdout: () => string; | ||
setup: () => void; | ||
teardown: () => void; | ||
}; | ||
|
||
// unknown JestWorkerFarm | ||
|
||
declare const unknownWorkerFarm: JestWorkerFarm<Record<string, unknown>>; | ||
|
||
expectError(unknownWorkerFarm.runTest()); | ||
expectError(unknownWorkerFarm.runTestAsync()); | ||
|
||
expectError(unknownWorkerFarm.getResult()); | ||
expectError(unknownWorkerFarm.isResult); | ||
|
||
expectError(unknownWorkerFarm.setup()); | ||
expectError(unknownWorkerFarm.teardown()); | ||
|
||
expectType<Promise<{forceExited: boolean}>>(unknownWorkerFarm.end()); | ||
expectType<NodeJS.ReadableStream>(unknownWorkerFarm.getStderr()); | ||
expectType<NodeJS.ReadableStream>(unknownWorkerFarm.getStdout()); | ||
|
||
// detected JestWorkerFarm | ||
|
||
declare const detectedWorkerFarm: JestWorkerFarm<typeof testWorker>; | ||
|
||
expectType<Promise<void>>(detectedWorkerFarm.runTest()); | ||
expectType<Promise<void>>(detectedWorkerFarm.runTestAsync()); | ||
|
||
expectError(detectedWorkerFarm.getResult()); | ||
expectError(detectedWorkerFarm.isResult); | ||
|
||
expectError(detectedWorkerFarm.setup()); | ||
expectError(detectedWorkerFarm.teardown()); | ||
|
||
expectError<Promise<void>>(detectedWorkerFarm.end()); | ||
expectType<Promise<{forceExited: boolean}>>(detectedWorkerFarm.end()); | ||
|
||
expectError<Promise<string>>(detectedWorkerFarm.getStderr()); | ||
expectType<NodeJS.ReadableStream>(detectedWorkerFarm.getStderr()); | ||
|
||
expectError<Promise<string>>(detectedWorkerFarm.getStdout()); | ||
expectType<NodeJS.ReadableStream>(detectedWorkerFarm.getStdout()); | ||
|
||
// typed JestWorkerFarm | ||
|
||
declare const typedWorkerFarm: JestWorkerFarm<TestWorker>; | ||
|
||
expectType<Promise<void>>(typedWorkerFarm.runTest()); | ||
|
||
expectError(typedWorkerFarm.isResult); | ||
expectError(typedWorkerFarm.runTestAsync()); | ||
|
||
expectError(typedWorkerFarm.setup()); | ||
expectError(typedWorkerFarm.teardown()); | ||
|
||
expectError<Promise<void>>(typedWorkerFarm.end()); | ||
expectType<Promise<{forceExited: boolean}>>(typedWorkerFarm.end()); | ||
|
||
expectError<Promise<string>>(typedWorkerFarm.getStderr()); | ||
expectType<NodeJS.ReadableStream>(typedWorkerFarm.getStderr()); | ||
|
||
expectError<Promise<string>>(typedWorkerFarm.getStdout()); | ||
expectType<NodeJS.ReadableStream>(typedWorkerFarm.getStdout()); |
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,26 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
export function runTest(): void {} | ||
export async function runTestAsync(): Promise<void> {} | ||
|
||
function getResult(): string { | ||
return 'result'; | ||
} | ||
export const isResult = true; | ||
|
||
// reserved keys should be excluded from returned type | ||
|
||
export function end(): void {} | ||
export function getStderr(): string { | ||
return 'get-err'; | ||
} | ||
export function getStdout(): string { | ||
return 'get-out'; | ||
} | ||
export function setup(): void {} | ||
export function teardown(): void {} |
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,12 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"composite": false, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"skipLibCheck": true, | ||
|
||
"types": ["node"] | ||
}, | ||
"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.