@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.
Files changed (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +413 -413
  3. package/dist/src/runner/isolated-loader.mjs +91 -91
  4. package/dist/src/runner/worker-loader.mjs +49 -49
  5. package/dist/tsconfig.publish.tsbuildinfo +1 -1
  6. package/package.json +12 -12
  7. package/src/GGBundleTest.ts +89 -89
  8. package/src/GGTest.ts +318 -318
  9. package/src/GGTestContext.ts +74 -74
  10. package/src/GGTestRunner.ts +308 -308
  11. package/src/GGTestRuntime.ts +265 -265
  12. package/src/GGTestRuntimeWorker.ts +159 -159
  13. package/src/GGTestSharedRef.ts +116 -116
  14. package/src/GGTestkitExtensionsDiscovery.ts +26 -26
  15. package/src/IGGLocalDiscoveryServer.ts +16 -16
  16. package/src/callOn/GGCallOnSelector.ts +61 -61
  17. package/src/callOn/GGContractClass.implement.ts +43 -43
  18. package/src/callOn/GGTestActionForLocatorOnCall.ts +134 -134
  19. package/src/callOn/TestableIPC.ts +81 -81
  20. package/src/callOn/callOn.ts +224 -224
  21. package/src/callOn/registerOnCallHandler.ts +123 -123
  22. package/src/index-node.ts +64 -64
  23. package/src/mockable/GGMockable.ts +22 -22
  24. package/src/mockable/GGMockableCall.ts +45 -45
  25. package/src/mockable/GGMockableIPC.ts +20 -20
  26. package/src/mockable/GGMockableInterceptor.ts +44 -44
  27. package/src/mockable/GGMockableInterceptorsServer.ts +69 -69
  28. package/src/mockable/mockable.ts +71 -71
  29. package/src/runner/InlineRunner.ts +47 -47
  30. package/src/runner/IsolatedRunner.ts +179 -179
  31. package/src/runner/RuntimeRunner.ts +15 -15
  32. package/src/runner/WorkerRunner.ts +179 -179
  33. package/src/runner/isolated-loader.mjs +91 -91
  34. package/src/runner/worker-loader.mjs +49 -49
  35. package/src/testers/GGCallInterceptor.ts +224 -224
  36. package/src/testers/GGMockWith.ts +92 -92
  37. package/src/testers/GGSpyWith.ts +115 -115
  38. package/src/testers/GGTestAction.ts +332 -332
  39. package/src/testers/GGTestComponent.ts +16 -16
  40. package/src/testers/GGTestSelector.ts +223 -223
  41. package/src/testers/IGGTestInterceptor.ts +10 -10
  42. package/src/testers/IGGTestWith.ts +15 -15
  43. package/src/testers/RuntimeSelector.ts +151 -151
  44. package/src/utils/GGExpectations.ts +78 -78
  45. package/src/utils/GGTestError.ts +36 -36
  46. package/src/utils/captureStack.ts +53 -53
@@ -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
+ }