@grest-ts/testkit 0.0.6 → 0.0.8
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 +13 -13
- 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/GGTestContext.ts
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import {GGContext} from "@grest-ts/context";
|
|
2
|
-
import {callOn, callOnCollection, GGTestCallOn, GGTestCallOnCollection} from "./callOn/callOn";
|
|
3
|
-
|
|
4
|
-
// Note: beforeAll, beforeEach, afterEach, afterAll are vitest globals
|
|
5
|
-
// Do NOT import them directly - it breaks worker threads that load this module
|
|
6
|
-
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// Test Collection Types
|
|
9
|
-
// ============================================================================
|
|
10
|
-
|
|
11
|
-
export class GGTestContext extends GGContext {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
public resetAfterEach(): this {
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
this.reset();
|
|
17
|
-
});
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Register APIs and services for testing.
|
|
23
|
-
* Returns `this` merged with test clients for all registered items.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* const alice = new GGTestContext("alice")
|
|
27
|
-
* .apisV2({
|
|
28
|
-
* chain: ChainApi, // HTTP API → test client
|
|
29
|
-
* services: {
|
|
30
|
-
* weather: WeatherService // Service class → testable access
|
|
31
|
-
* }
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* alice.chain.getWeather({...}) // HTTP test client
|
|
35
|
-
* alice.services.weather.getWeather({...}) // Testable service
|
|
36
|
-
*/
|
|
37
|
-
public apis<T extends object>(apis: T): this & GGTestCallOnCollection<T> {
|
|
38
|
-
Object.assign(this, callOnCollection(apis, this));
|
|
39
|
-
return this as this & GGTestCallOnCollection<T>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Call a method on an API or service within this context.
|
|
44
|
-
* Creates and caches test clients/proxies for reuse.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* alice.callOn(ChainApi).getWeather({city: "NYC"})
|
|
48
|
-
* alice.callOn(WeatherService).getWeather("NYC")
|
|
49
|
-
*/
|
|
50
|
-
public callOn<T extends object>(target: T): GGTestCallOn<T> {
|
|
51
|
-
return callOn(target, this)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public beforeAll(callback: () => void): this {
|
|
55
|
-
beforeAll(() => this.run(callback));
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public beforeEach(callback: () => void): this {
|
|
60
|
-
beforeEach(() => this.run(callback));
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public afterEach(callback: () => void): this {
|
|
65
|
-
afterEach(() => this.run(callback));
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public afterAll(callback: () => void): this {
|
|
70
|
-
afterAll(() => this.run(callback));
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
1
|
+
import {GGContext} from "@grest-ts/context";
|
|
2
|
+
import {callOn, callOnCollection, GGTestCallOn, GGTestCallOnCollection} from "./callOn/callOn";
|
|
3
|
+
|
|
4
|
+
// Note: beforeAll, beforeEach, afterEach, afterAll are vitest globals
|
|
5
|
+
// Do NOT import them directly - it breaks worker threads that load this module
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Test Collection Types
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
export class GGTestContext extends GGContext {
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
public resetAfterEach(): this {
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
this.reset();
|
|
17
|
+
});
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Register APIs and services for testing.
|
|
23
|
+
* Returns `this` merged with test clients for all registered items.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const alice = new GGTestContext("alice")
|
|
27
|
+
* .apisV2({
|
|
28
|
+
* chain: ChainApi, // HTTP API → test client
|
|
29
|
+
* services: {
|
|
30
|
+
* weather: WeatherService // Service class → testable access
|
|
31
|
+
* }
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* alice.chain.getWeather({...}) // HTTP test client
|
|
35
|
+
* alice.services.weather.getWeather({...}) // Testable service
|
|
36
|
+
*/
|
|
37
|
+
public apis<T extends object>(apis: T): this & GGTestCallOnCollection<T> {
|
|
38
|
+
Object.assign(this, callOnCollection(apis, this));
|
|
39
|
+
return this as this & GGTestCallOnCollection<T>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Call a method on an API or service within this context.
|
|
44
|
+
* Creates and caches test clients/proxies for reuse.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* alice.callOn(ChainApi).getWeather({city: "NYC"})
|
|
48
|
+
* alice.callOn(WeatherService).getWeather("NYC")
|
|
49
|
+
*/
|
|
50
|
+
public callOn<T extends object>(target: T): GGTestCallOn<T> {
|
|
51
|
+
return callOn(target, this)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public beforeAll(callback: () => void): this {
|
|
55
|
+
beforeAll(() => this.run(callback));
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public beforeEach(callback: () => void): this {
|
|
60
|
+
beforeEach(() => this.run(callback));
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public afterEach(callback: () => void): this {
|
|
65
|
+
afterEach(() => this.run(callback));
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public afterAll(callback: () => void): this {
|
|
70
|
+
afterAll(() => this.run(callback));
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|