@grest-ts/testkit 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +413 -413
- package/dist/src/runner/isolated-loader.mjs +91 -91
- package/dist/src/runner/worker-loader.mjs +49 -49
- package/dist/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/src/GGBundleTest.ts +89 -89
- package/src/GGTest.ts +318 -318
- package/src/GGTestContext.ts +74 -74
- package/src/GGTestRunner.ts +308 -308
- package/src/GGTestRuntime.ts +265 -265
- package/src/GGTestRuntimeWorker.ts +159 -159
- package/src/GGTestSharedRef.ts +116 -116
- package/src/GGTestkitExtensionsDiscovery.ts +26 -26
- package/src/IGGLocalDiscoveryServer.ts +16 -16
- package/src/callOn/GGCallOnSelector.ts +61 -61
- package/src/callOn/GGContractClass.implement.ts +43 -43
- package/src/callOn/GGTestActionForLocatorOnCall.ts +134 -134
- package/src/callOn/TestableIPC.ts +81 -81
- package/src/callOn/callOn.ts +224 -224
- package/src/callOn/registerOnCallHandler.ts +123 -123
- package/src/index-node.ts +64 -64
- package/src/mockable/GGMockable.ts +22 -22
- package/src/mockable/GGMockableCall.ts +45 -45
- package/src/mockable/GGMockableIPC.ts +20 -20
- package/src/mockable/GGMockableInterceptor.ts +44 -44
- package/src/mockable/GGMockableInterceptorsServer.ts +69 -69
- package/src/mockable/mockable.ts +71 -71
- package/src/runner/InlineRunner.ts +47 -47
- package/src/runner/IsolatedRunner.ts +179 -179
- package/src/runner/RuntimeRunner.ts +15 -15
- package/src/runner/WorkerRunner.ts +179 -179
- package/src/runner/isolated-loader.mjs +91 -91
- package/src/runner/worker-loader.mjs +49 -49
- package/src/testers/GGCallInterceptor.ts +224 -224
- package/src/testers/GGMockWith.ts +92 -92
- package/src/testers/GGSpyWith.ts +115 -115
- package/src/testers/GGTestAction.ts +332 -332
- package/src/testers/GGTestComponent.ts +16 -16
- package/src/testers/GGTestSelector.ts +223 -223
- package/src/testers/IGGTestInterceptor.ts +10 -10
- package/src/testers/IGGTestWith.ts +15 -15
- package/src/testers/RuntimeSelector.ts +151 -151
- package/src/utils/GGExpectations.ts +78 -78
- package/src/utils/GGTestError.ts +36 -36
- package/src/utils/captureStack.ts +53 -53
package/src/testers/GGSpyWith.ts
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import {captureStackSourceFile} from "../utils/captureStack";
|
|
2
|
-
import {GGExpectations} from "../utils/GGExpectations";
|
|
3
|
-
import {Raw} from "@grest-ts/schema";
|
|
4
|
-
import {ConstructorOf, DeepPartial} from "@grest-ts/common";
|
|
5
|
-
import {GG_TEST_RUNNER, GGTestRunner} from "../GGTestRunner";
|
|
6
|
-
import {IGGTestWith} from "./IGGTestWith";
|
|
7
|
-
import {IGGTestInterceptor} from "./IGGTestInterceptor";
|
|
8
|
-
import {GGCallInterceptor, GGCallInterceptorConfig} from "./GGCallInterceptor";
|
|
9
|
-
|
|
10
|
-
type InterceptorFactory = new (runner: GGTestRunner, config: any) => GGCallInterceptor;
|
|
11
|
-
|
|
12
|
-
export class GGSpyWith<RequestBody = any, ResponseData = any, ErrorsUnion = any> implements IGGTestWith {
|
|
13
|
-
|
|
14
|
-
private readonly interceptorFactory: InterceptorFactory;
|
|
15
|
-
private readonly interceptorConfig: Record<string, any>;
|
|
16
|
-
private readonly definedInSourceFile: string;
|
|
17
|
-
|
|
18
|
-
private readonly _expectInput: GGExpectations<RequestBody> = new GGExpectations()
|
|
19
|
-
private _expectError: ConstructorOf<ErrorsUnion>
|
|
20
|
-
private readonly _expectOutput: GGExpectations<ResponseData> = new GGExpectations()
|
|
21
|
-
|
|
22
|
-
private activeExpect: GGExpectations<any>;
|
|
23
|
-
|
|
24
|
-
private _sleep: number;
|
|
25
|
-
private _times: number = 1;
|
|
26
|
-
|
|
27
|
-
constructor(interceptorFactory: InterceptorFactory, config: Record<string, any>) {
|
|
28
|
-
this.interceptorFactory = interceptorFactory;
|
|
29
|
-
this.interceptorConfig = config;
|
|
30
|
-
this.definedInSourceFile = captureStackSourceFile();
|
|
31
|
-
this.activeExpect = this._expectInput;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public createInterceptor(): IGGTestInterceptor {
|
|
35
|
-
const test = GG_TEST_RUNNER.get();
|
|
36
|
-
const config: GGCallInterceptorConfig = {
|
|
37
|
-
...this.interceptorConfig,
|
|
38
|
-
definedInSourceFile: this.definedInSourceFile,
|
|
39
|
-
sleep: this._sleep,
|
|
40
|
-
times: this._times,
|
|
41
|
-
passThrough: true,
|
|
42
|
-
inputExpectations: this._expectInput,
|
|
43
|
-
outputExpectations: this._expectOutput,
|
|
44
|
-
expectError: this._expectError
|
|
45
|
-
};
|
|
46
|
-
return new this.interceptorFactory(test, config);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Wait ms before returning data.
|
|
51
|
-
*/
|
|
52
|
-
public sleep(timeMs: number): this {
|
|
53
|
-
this._sleep = timeMs;
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Expect this mock to be called amount of times.
|
|
59
|
-
*/
|
|
60
|
-
public times(amount: number): this {
|
|
61
|
-
this._times = amount;
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public get response(): GGSpyWith<ResponseData, never, never> {
|
|
66
|
-
this.activeExpect = this._expectOutput;
|
|
67
|
-
this._expectOutput.flush();
|
|
68
|
-
return this as any;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public toBeError<Type extends ConstructorOf<ErrorsUnion>>(type: Type): GGSpyWith<Extract<ErrorsUnion, InstanceType<Type>>, never, never> {
|
|
72
|
-
this._expectError = type;
|
|
73
|
-
this._expectOutput.flush();
|
|
74
|
-
return this as any;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public toEqual(expectedData: Raw<RequestBody>): this {
|
|
78
|
-
this.activeExpect.toEqual(expectedData as RequestBody)
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public toMatchObject(expectedData: DeepPartial<Raw<RequestBody>>): this {
|
|
83
|
-
this.activeExpect.toMatchObject(expectedData as RequestBody)
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public responseToMatchObject(expectedData: DeepPartial<Raw<ResponseData>>): this {
|
|
88
|
-
this._expectOutput.toMatchObject(expectedData as ResponseData)
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public toBeUndefined(): this {
|
|
93
|
-
this.activeExpect.toBeUndefined()
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public toHaveLength(length: number): this {
|
|
98
|
-
this.activeExpect.toHaveLength(length)
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public arrayToContain<Item extends RequestBody extends Array<infer R> ? R : never>(...items: Partial<Raw<Item>>[]): this {
|
|
103
|
-
this.activeExpect.arrayToContain(...items)
|
|
104
|
-
return this;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public arrayToContainEqual<Item extends RequestBody extends Array<infer R> ? R : never>(...items: Partial<Raw<Item>>[]): this {
|
|
108
|
-
this.activeExpect.arrayToContainEqual(...items)
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public requiresWaitFor(): boolean {
|
|
113
|
-
return this.interceptorConfig.requiresWaitFor === true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
1
|
+
import {captureStackSourceFile} from "../utils/captureStack";
|
|
2
|
+
import {GGExpectations} from "../utils/GGExpectations";
|
|
3
|
+
import {Raw} from "@grest-ts/schema";
|
|
4
|
+
import {ConstructorOf, DeepPartial} from "@grest-ts/common";
|
|
5
|
+
import {GG_TEST_RUNNER, GGTestRunner} from "../GGTestRunner";
|
|
6
|
+
import {IGGTestWith} from "./IGGTestWith";
|
|
7
|
+
import {IGGTestInterceptor} from "./IGGTestInterceptor";
|
|
8
|
+
import {GGCallInterceptor, GGCallInterceptorConfig} from "./GGCallInterceptor";
|
|
9
|
+
|
|
10
|
+
type InterceptorFactory = new (runner: GGTestRunner, config: any) => GGCallInterceptor;
|
|
11
|
+
|
|
12
|
+
export class GGSpyWith<RequestBody = any, ResponseData = any, ErrorsUnion = any> implements IGGTestWith {
|
|
13
|
+
|
|
14
|
+
private readonly interceptorFactory: InterceptorFactory;
|
|
15
|
+
private readonly interceptorConfig: Record<string, any>;
|
|
16
|
+
private readonly definedInSourceFile: string;
|
|
17
|
+
|
|
18
|
+
private readonly _expectInput: GGExpectations<RequestBody> = new GGExpectations()
|
|
19
|
+
private _expectError: ConstructorOf<ErrorsUnion>
|
|
20
|
+
private readonly _expectOutput: GGExpectations<ResponseData> = new GGExpectations()
|
|
21
|
+
|
|
22
|
+
private activeExpect: GGExpectations<any>;
|
|
23
|
+
|
|
24
|
+
private _sleep: number;
|
|
25
|
+
private _times: number = 1;
|
|
26
|
+
|
|
27
|
+
constructor(interceptorFactory: InterceptorFactory, config: Record<string, any>) {
|
|
28
|
+
this.interceptorFactory = interceptorFactory;
|
|
29
|
+
this.interceptorConfig = config;
|
|
30
|
+
this.definedInSourceFile = captureStackSourceFile();
|
|
31
|
+
this.activeExpect = this._expectInput;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public createInterceptor(): IGGTestInterceptor {
|
|
35
|
+
const test = GG_TEST_RUNNER.get();
|
|
36
|
+
const config: GGCallInterceptorConfig = {
|
|
37
|
+
...this.interceptorConfig,
|
|
38
|
+
definedInSourceFile: this.definedInSourceFile,
|
|
39
|
+
sleep: this._sleep,
|
|
40
|
+
times: this._times,
|
|
41
|
+
passThrough: true,
|
|
42
|
+
inputExpectations: this._expectInput,
|
|
43
|
+
outputExpectations: this._expectOutput,
|
|
44
|
+
expectError: this._expectError
|
|
45
|
+
};
|
|
46
|
+
return new this.interceptorFactory(test, config);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Wait ms before returning data.
|
|
51
|
+
*/
|
|
52
|
+
public sleep(timeMs: number): this {
|
|
53
|
+
this._sleep = timeMs;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Expect this mock to be called amount of times.
|
|
59
|
+
*/
|
|
60
|
+
public times(amount: number): this {
|
|
61
|
+
this._times = amount;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public get response(): GGSpyWith<ResponseData, never, never> {
|
|
66
|
+
this.activeExpect = this._expectOutput;
|
|
67
|
+
this._expectOutput.flush();
|
|
68
|
+
return this as any;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public toBeError<Type extends ConstructorOf<ErrorsUnion>>(type: Type): GGSpyWith<Extract<ErrorsUnion, InstanceType<Type>>, never, never> {
|
|
72
|
+
this._expectError = type;
|
|
73
|
+
this._expectOutput.flush();
|
|
74
|
+
return this as any;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public toEqual(expectedData: Raw<RequestBody>): this {
|
|
78
|
+
this.activeExpect.toEqual(expectedData as RequestBody)
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public toMatchObject(expectedData: DeepPartial<Raw<RequestBody>>): this {
|
|
83
|
+
this.activeExpect.toMatchObject(expectedData as RequestBody)
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public responseToMatchObject(expectedData: DeepPartial<Raw<ResponseData>>): this {
|
|
88
|
+
this._expectOutput.toMatchObject(expectedData as ResponseData)
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public toBeUndefined(): this {
|
|
93
|
+
this.activeExpect.toBeUndefined()
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public toHaveLength(length: number): this {
|
|
98
|
+
this.activeExpect.toHaveLength(length)
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public arrayToContain<Item extends RequestBody extends Array<infer R> ? R : never>(...items: Partial<Raw<Item>>[]): this {
|
|
103
|
+
this.activeExpect.arrayToContain(...items)
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public arrayToContainEqual<Item extends RequestBody extends Array<infer R> ? R : never>(...items: Partial<Raw<Item>>[]): this {
|
|
108
|
+
this.activeExpect.arrayToContainEqual(...items)
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public requiresWaitFor(): boolean {
|
|
113
|
+
return this.interceptorConfig.requiresWaitFor === true;
|
|
114
|
+
}
|
|
115
|
+
}
|