Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Fixes

- `[jest-worker]` Make `JestWorkerFarm` helper type to include methods of worker module that take more than one argument ([#12839](https://github.com/facebook/jest/pull/12839))

### Chore & Maintenance

- `[docs]` Updated docs to indicate that `jest-environment-jsdom` is a separate package [#12828](https://github.com/facebook/jest/issues/12828)
Expand Down
26 changes: 22 additions & 4 deletions packages/jest-worker/__typetests__/jest-worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type {JestWorkerFarm} from 'jest-worker';
import type * as testWorker from './testWorker';

type TestWorker = {
runTest: () => void;
runTest: (a: string, b: number) => void;
doSomething: () => void;
isResult: boolean;
end: () => void; // reserved keys should be excluded from returned type
getStderr: () => string;
Expand Down Expand Up @@ -40,8 +41,20 @@ expectType<NodeJS.ReadableStream>(unknownWorkerFarm.getStdout());

declare const detectedWorkerFarm: JestWorkerFarm<typeof testWorker>;

expectType<Promise<void>>(detectedWorkerFarm.runTest());
expectType<Promise<void>>(detectedWorkerFarm.runTestAsync());
expectType<Promise<void>>(detectedWorkerFarm.runTest('abc', true));
expectType<Promise<void>>(detectedWorkerFarm.runTestAsync(123, 456));

expectType<Promise<void>>(detectedWorkerFarm.doSomething());
expectType<Promise<void>>(detectedWorkerFarm.doSomething());
expectType<Promise<void>>(detectedWorkerFarm.doSomethingAsync());
expectType<Promise<void>>(detectedWorkerFarm.doSomethingAsync());

expectError(detectedWorkerFarm.runTest());
expectError(detectedWorkerFarm.runTest('abc'));
expectError(detectedWorkerFarm.runTestAsync());
expectError(detectedWorkerFarm.runTestAsync(123));
expectError(detectedWorkerFarm.doSomething(123));
expectError(detectedWorkerFarm.doSomethingAsync('abc'));

expectError(detectedWorkerFarm.getResult());
expectError(detectedWorkerFarm.isResult);
Expand All @@ -62,7 +75,12 @@ expectType<NodeJS.ReadableStream>(detectedWorkerFarm.getStdout());

declare const typedWorkerFarm: JestWorkerFarm<TestWorker>;

expectType<Promise<void>>(typedWorkerFarm.runTest());
expectType<Promise<void>>(typedWorkerFarm.runTest('abc', 123));
expectType<Promise<void>>(typedWorkerFarm.doSomething());

expectError(typedWorkerFarm.runTest());
expectError(typedWorkerFarm.runTest('abc'));
expectError(typedWorkerFarm.doSomething('abc'));

expectError(typedWorkerFarm.isResult);
expectError(typedWorkerFarm.runTestAsync());
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-worker/__typetests__/testWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/

export function runTest(): void {}
export async function runTestAsync(): Promise<void> {}
export function runTest(a: string, b: boolean): void {}
export async function runTestAsync(c: number, d: number): Promise<void> {}

export function doSomething(): void {}
export async function doSomethingAsync(): Promise<void> {}

function getResult(): string {
return 'result';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-worker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {ResourceLimits} from 'worker_threads';
type ReservedKeys = 'end' | 'getStderr' | 'getStdout' | 'setup' | 'teardown';
type ExcludeReservedKeys<K> = Exclude<K, ReservedKeys>;

type FunctionLike = (args: any) => unknown;
type FunctionLike = (...args: any) => unknown;

type MethodLikeKeys<T> = {
[K in keyof T]: T[K] extends FunctionLike ? K : never;
Expand Down