/
jest-worker.test.ts
98 lines (71 loc) · 3.36 KB
/
jest-worker.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* 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: (a: string, b: number) => void;
doSomething: () => 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('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);
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('abc', 123));
expectType<Promise<void>>(typedWorkerFarm.doSomething());
expectError(typedWorkerFarm.runTest());
expectError(typedWorkerFarm.runTest('abc'));
expectError(typedWorkerFarm.doSomething('abc'));
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());