@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
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Isolated process loader for ES modules
|
|
3
|
-
* This file is the entry point for isolated test processes
|
|
4
|
-
*
|
|
5
|
-
* Usage: npx tsx isolated-loader.mjs <runtime-source-url>
|
|
6
|
-
* Environment: GG_ISOLATED_CONFIG must be set with JSON config
|
|
7
|
-
*/
|
|
8
|
-
import {register} from 'tsx/esm/api';
|
|
9
|
-
import {pathToFileURL} from 'url';
|
|
10
|
-
|
|
11
|
-
// Register tsx to handle TypeScript with ESM
|
|
12
|
-
register();
|
|
13
|
-
|
|
14
|
-
// Get the runtime source URL from command line args (can be file:// URL or path)
|
|
15
|
-
let runtimeSourceUrl = process.argv[2];
|
|
16
|
-
if (!runtimeSourceUrl) {
|
|
17
|
-
console.error('Usage: npx tsx isolated-loader.mjs <runtime-source-url>');
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Convert to file:// URL if it's a path
|
|
22
|
-
if (!runtimeSourceUrl.startsWith('file:')) {
|
|
23
|
-
runtimeSourceUrl = pathToFileURL(runtimeSourceUrl).href;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const GG_ISOLATED_CONFIG = "GG_ISOLATED_CONFIG";
|
|
27
|
-
const PROCESS_READY = "IsolatedRunner:READY";
|
|
28
|
-
|
|
29
|
-
// Get config from environment
|
|
30
|
-
const configJson = process.env[GG_ISOLATED_CONFIG];
|
|
31
|
-
if (!configJson) {
|
|
32
|
-
console.error('GG_ISOLATED_CONFIG not set');
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Import runtime and testkit dependencies
|
|
37
|
-
const {GGRuntime} = await import('@grest-ts/runtime');
|
|
38
|
-
const {GGTestRuntimeWorker} = await import('@grest-ts/testkit');
|
|
39
|
-
const {GGLog} = await import('@grest-ts/logger');
|
|
40
|
-
|
|
41
|
-
const config = JSON.parse(configJson);
|
|
42
|
-
|
|
43
|
-
// Override cli() to intercept runtime startup in isolated mode
|
|
44
|
-
|
|
45
|
-
GGRuntime.cli = async function(moduleUrl) {
|
|
46
|
-
// Still set SOURCE_MODULE_URL for testkit compatibility
|
|
47
|
-
this.SOURCE_MODULE_URL = moduleUrl;
|
|
48
|
-
|
|
49
|
-
// Start the runtime via test worker instead of normal startup
|
|
50
|
-
const controlClient = new GGTestRuntimeWorker(config);
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
await controlClient.start(() => new this());
|
|
54
|
-
|
|
55
|
-
// Signal to parent process that we're ready
|
|
56
|
-
console.log(PROCESS_READY);
|
|
57
|
-
|
|
58
|
-
const stopRuntime = async () => {
|
|
59
|
-
// Stop the GGRuntime but keep process alive for log retrieval
|
|
60
|
-
await controlClient.stopRuntime();
|
|
61
|
-
console.log('IsolatedRunner:RUNTIME_STOPPED');
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const shutdown = async () => {
|
|
65
|
-
// Fully shutdown process
|
|
66
|
-
await controlClient.shutdown();
|
|
67
|
-
process.exit(0);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Listen for commands via stdin
|
|
71
|
-
process.stdin.setEncoding('utf8');
|
|
72
|
-
process.stdin.on('data', (data) => {
|
|
73
|
-
const message = data.toString().trim();
|
|
74
|
-
if (message === 'STOP_RUNTIME') {
|
|
75
|
-
GGLog.debug({name: 'IsolatedLoader'}, 'Received stop runtime command');
|
|
76
|
-
stopRuntime();
|
|
77
|
-
} else if (message === 'SHUTDOWN') {
|
|
78
|
-
GGLog.debug({name: 'IsolatedLoader'}, 'Received shutdown command');
|
|
79
|
-
shutdown();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
process.on('SIGTERM', shutdown);
|
|
83
|
-
process.on('SIGINT', shutdown);
|
|
84
|
-
} catch (err) {
|
|
85
|
-
GGLog.error({name: 'IsolatedLoader'}, 'Failed to start isolated runtime', err);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// Import the runtime source - this will call the overridden cli()
|
|
91
|
-
await import(runtimeSourceUrl);
|
|
1
|
+
/**
|
|
2
|
+
* Isolated process loader for ES modules
|
|
3
|
+
* This file is the entry point for isolated test processes
|
|
4
|
+
*
|
|
5
|
+
* Usage: npx tsx isolated-loader.mjs <runtime-source-url>
|
|
6
|
+
* Environment: GG_ISOLATED_CONFIG must be set with JSON config
|
|
7
|
+
*/
|
|
8
|
+
import {register} from 'tsx/esm/api';
|
|
9
|
+
import {pathToFileURL} from 'url';
|
|
10
|
+
|
|
11
|
+
// Register tsx to handle TypeScript with ESM
|
|
12
|
+
register();
|
|
13
|
+
|
|
14
|
+
// Get the runtime source URL from command line args (can be file:// URL or path)
|
|
15
|
+
let runtimeSourceUrl = process.argv[2];
|
|
16
|
+
if (!runtimeSourceUrl) {
|
|
17
|
+
console.error('Usage: npx tsx isolated-loader.mjs <runtime-source-url>');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Convert to file:// URL if it's a path
|
|
22
|
+
if (!runtimeSourceUrl.startsWith('file:')) {
|
|
23
|
+
runtimeSourceUrl = pathToFileURL(runtimeSourceUrl).href;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const GG_ISOLATED_CONFIG = "GG_ISOLATED_CONFIG";
|
|
27
|
+
const PROCESS_READY = "IsolatedRunner:READY";
|
|
28
|
+
|
|
29
|
+
// Get config from environment
|
|
30
|
+
const configJson = process.env[GG_ISOLATED_CONFIG];
|
|
31
|
+
if (!configJson) {
|
|
32
|
+
console.error('GG_ISOLATED_CONFIG not set');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Import runtime and testkit dependencies
|
|
37
|
+
const {GGRuntime} = await import('@grest-ts/runtime');
|
|
38
|
+
const {GGTestRuntimeWorker} = await import('@grest-ts/testkit');
|
|
39
|
+
const {GGLog} = await import('@grest-ts/logger');
|
|
40
|
+
|
|
41
|
+
const config = JSON.parse(configJson);
|
|
42
|
+
|
|
43
|
+
// Override cli() to intercept runtime startup in isolated mode
|
|
44
|
+
|
|
45
|
+
GGRuntime.cli = async function(moduleUrl) {
|
|
46
|
+
// Still set SOURCE_MODULE_URL for testkit compatibility
|
|
47
|
+
this.SOURCE_MODULE_URL = moduleUrl;
|
|
48
|
+
|
|
49
|
+
// Start the runtime via test worker instead of normal startup
|
|
50
|
+
const controlClient = new GGTestRuntimeWorker(config);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
await controlClient.start(() => new this());
|
|
54
|
+
|
|
55
|
+
// Signal to parent process that we're ready
|
|
56
|
+
console.log(PROCESS_READY);
|
|
57
|
+
|
|
58
|
+
const stopRuntime = async () => {
|
|
59
|
+
// Stop the GGRuntime but keep process alive for log retrieval
|
|
60
|
+
await controlClient.stopRuntime();
|
|
61
|
+
console.log('IsolatedRunner:RUNTIME_STOPPED');
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const shutdown = async () => {
|
|
65
|
+
// Fully shutdown process
|
|
66
|
+
await controlClient.shutdown();
|
|
67
|
+
process.exit(0);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Listen for commands via stdin
|
|
71
|
+
process.stdin.setEncoding('utf8');
|
|
72
|
+
process.stdin.on('data', (data) => {
|
|
73
|
+
const message = data.toString().trim();
|
|
74
|
+
if (message === 'STOP_RUNTIME') {
|
|
75
|
+
GGLog.debug({name: 'IsolatedLoader'}, 'Received stop runtime command');
|
|
76
|
+
stopRuntime();
|
|
77
|
+
} else if (message === 'SHUTDOWN') {
|
|
78
|
+
GGLog.debug({name: 'IsolatedLoader'}, 'Received shutdown command');
|
|
79
|
+
shutdown();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
process.on('SIGTERM', shutdown);
|
|
83
|
+
process.on('SIGINT', shutdown);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
GGLog.error({name: 'IsolatedLoader'}, 'Failed to start isolated runtime', err);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Import the runtime source - this will call the overridden cli()
|
|
91
|
+
await import(runtimeSourceUrl);
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Worker loader for ES modules
|
|
3
|
-
* This file is loaded by worker threads to execute test runtimes
|
|
4
|
-
*
|
|
5
|
-
* workerData is GGTestEnvConfig: { executablePath, testRouterPort, testId, runtimeId, initialCommands }
|
|
6
|
-
*/
|
|
7
|
-
import {register} from 'tsx/esm/api';
|
|
8
|
-
import {parentPort, workerData} from 'worker_threads';
|
|
9
|
-
|
|
10
|
-
// Register tsx to handle TypeScript with ESM
|
|
11
|
-
register();
|
|
12
|
-
|
|
13
|
-
// Catch unhandled errors in worker thread
|
|
14
|
-
process.on('uncaughtException', (err) => {
|
|
15
|
-
console.error(`[WorkerThread ${workerData?.runtimeId}] Uncaught exception:`, err);
|
|
16
|
-
});
|
|
17
|
-
process.on('unhandledRejection', (reason) => {
|
|
18
|
-
console.error(`[WorkerThread ${workerData?.runtimeId}] Unhandled rejection:`, reason);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// workerData is GGTestEnvConfig directly
|
|
22
|
-
const config = workerData;
|
|
23
|
-
|
|
24
|
-
// Import control client from @grest-ts/testkit
|
|
25
|
-
const {GGTestRuntimeWorker} = await import('@grest-ts/testkit');
|
|
26
|
-
|
|
27
|
-
// Create control client
|
|
28
|
-
const controlClient = new GGTestRuntimeWorker(config);
|
|
29
|
-
|
|
30
|
-
// Start the runtime
|
|
31
|
-
try {
|
|
32
|
-
await controlClient.start();
|
|
33
|
-
parentPort.postMessage({type: 'ready'});
|
|
34
|
-
} catch (err) {
|
|
35
|
-
parentPort.postMessage({type: 'error', error: err.stack || err.message});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Handle messages from parent
|
|
39
|
-
parentPort.on('message', async (msg) => {
|
|
40
|
-
if (msg.type === 'stopRuntime') {
|
|
41
|
-
// Stop the GGRuntime but keep worker alive for log retrieval
|
|
42
|
-
await controlClient.stopRuntime();
|
|
43
|
-
parentPort.postMessage({type: 'runtimeStopped'});
|
|
44
|
-
} else if (msg.type === 'shutdown') {
|
|
45
|
-
// Fully shutdown worker
|
|
46
|
-
await controlClient.shutdown();
|
|
47
|
-
process.exit(0);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Worker loader for ES modules
|
|
3
|
+
* This file is loaded by worker threads to execute test runtimes
|
|
4
|
+
*
|
|
5
|
+
* workerData is GGTestEnvConfig: { executablePath, testRouterPort, testId, runtimeId, initialCommands }
|
|
6
|
+
*/
|
|
7
|
+
import {register} from 'tsx/esm/api';
|
|
8
|
+
import {parentPort, workerData} from 'worker_threads';
|
|
9
|
+
|
|
10
|
+
// Register tsx to handle TypeScript with ESM
|
|
11
|
+
register();
|
|
12
|
+
|
|
13
|
+
// Catch unhandled errors in worker thread
|
|
14
|
+
process.on('uncaughtException', (err) => {
|
|
15
|
+
console.error(`[WorkerThread ${workerData?.runtimeId}] Uncaught exception:`, err);
|
|
16
|
+
});
|
|
17
|
+
process.on('unhandledRejection', (reason) => {
|
|
18
|
+
console.error(`[WorkerThread ${workerData?.runtimeId}] Unhandled rejection:`, reason);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// workerData is GGTestEnvConfig directly
|
|
22
|
+
const config = workerData;
|
|
23
|
+
|
|
24
|
+
// Import control client from @grest-ts/testkit
|
|
25
|
+
const {GGTestRuntimeWorker} = await import('@grest-ts/testkit');
|
|
26
|
+
|
|
27
|
+
// Create control client
|
|
28
|
+
const controlClient = new GGTestRuntimeWorker(config);
|
|
29
|
+
|
|
30
|
+
// Start the runtime
|
|
31
|
+
try {
|
|
32
|
+
await controlClient.start();
|
|
33
|
+
parentPort.postMessage({type: 'ready'});
|
|
34
|
+
} catch (err) {
|
|
35
|
+
parentPort.postMessage({type: 'error', error: err.stack || err.message});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Handle messages from parent
|
|
39
|
+
parentPort.on('message', async (msg) => {
|
|
40
|
+
if (msg.type === 'stopRuntime') {
|
|
41
|
+
// Stop the GGRuntime but keep worker alive for log retrieval
|
|
42
|
+
await controlClient.stopRuntime();
|
|
43
|
+
parentPort.postMessage({type: 'runtimeStopped'});
|
|
44
|
+
} else if (msg.type === 'shutdown') {
|
|
45
|
+
// Fully shutdown worker
|
|
46
|
+
await controlClient.shutdown();
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
});
|