@grest-ts/testkit 0.0.5 → 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 +418 -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,89 +1,89 @@
1
- import {describe, test, expect, beforeAll} from "vitest";
2
- import {fileURLToPath} from "url";
3
- import type {BuildResult, Plugin} from "esbuild";
4
-
5
- const FORBIDDEN_SYMBOLS = {
6
- IPC: ['IPCServer', 'IPCClient', 'IPCSocket'],
7
- 'discovery-local': [
8
- 'GGLocalDiscoveryClient',
9
- 'GGLocalDiscoveryResilientClient',
10
- 'GGLocalDiscoveryServer',
11
- ],
12
- testkit: [
13
- 'GGTestRunner',
14
- 'GGTestRuntime',
15
- 'startWorker',
16
- 'startInline',
17
- 'startIsolated',
18
- ],
19
- } as const;
20
-
21
- interface GGBundleTestOptions {
22
- entryPoint: string;
23
- }
24
-
25
- export class GGBundleTest {
26
-
27
- static verify(options: GGBundleTestOptions) {
28
- const entryPoint = options.entryPoint.startsWith('file://')
29
- ? fileURLToPath(options.entryPoint)
30
- : options.entryPoint;
31
-
32
- describe("production bundle", () => {
33
- let result: BuildResult;
34
- let bundleText: string;
35
-
36
- beforeAll(async () => {
37
- const esbuild = await import("esbuild");
38
-
39
- const externalizeNonGG: Plugin = {
40
- name: 'externalize-non-gg',
41
- setup(build) {
42
- build.onResolve({filter: /./}, args => {
43
- // Only externalize import statements, not entry points
44
- if (args.kind !== 'import-statement' && args.kind !== 'dynamic-import') return null;
45
- // Keep relative/absolute paths bundled
46
- if (args.path.startsWith('.') || args.path.startsWith('/')) return null;
47
- // Keep @grest-ts/* packages bundled
48
- if (args.path.startsWith('@grest-ts/')) return null;
49
- return {path: args.path, external: true};
50
- });
51
- }
52
- };
53
-
54
- result = await esbuild.build({
55
- entryPoints: [entryPoint],
56
- bundle: true,
57
- write: false,
58
- platform: 'node',
59
- format: 'esm',
60
- define: {'process.env.NODE_ENV': '"production"'},
61
- plugins: [externalizeNonGG],
62
- });
63
-
64
- bundleText = result.outputFiles!.map(f => f.text).join('\n');
65
- });
66
-
67
- test("bundle has no errors", () => {
68
- expect(result.errors).toHaveLength(0);
69
- });
70
-
71
- test("bundle is non-trivially sized", () => {
72
- expect(bundleText.length).toBeGreaterThan(100);
73
- });
74
-
75
- for (const [group, symbols] of Object.entries(FORBIDDEN_SYMBOLS)) {
76
- for (const symbol of symbols) {
77
- test(`does not contain dev-only symbol: ${symbol} (${group})`, () => {
78
- // Match actual definitions (var X = class, class X, function X)
79
- // but not dead-code references like: const { X } = await null
80
- const definitionPattern = new RegExp(
81
- `\\b(var|let|const|class|function)\\s+${symbol}\\b`
82
- );
83
- expect(bundleText).not.toMatch(definitionPattern);
84
- });
85
- }
86
- }
87
- });
88
- }
89
- }
1
+ import {describe, test, expect, beforeAll} from "vitest";
2
+ import {fileURLToPath} from "url";
3
+ import type {BuildResult, Plugin} from "esbuild";
4
+
5
+ const FORBIDDEN_SYMBOLS = {
6
+ IPC: ['IPCServer', 'IPCClient', 'IPCSocket'],
7
+ 'discovery-local': [
8
+ 'GGLocalDiscoveryClient',
9
+ 'GGLocalDiscoveryResilientClient',
10
+ 'GGLocalDiscoveryServer',
11
+ ],
12
+ testkit: [
13
+ 'GGTestRunner',
14
+ 'GGTestRuntime',
15
+ 'startWorker',
16
+ 'startInline',
17
+ 'startIsolated',
18
+ ],
19
+ } as const;
20
+
21
+ interface GGBundleTestOptions {
22
+ entryPoint: string;
23
+ }
24
+
25
+ export class GGBundleTest {
26
+
27
+ static verify(options: GGBundleTestOptions) {
28
+ const entryPoint = options.entryPoint.startsWith('file://')
29
+ ? fileURLToPath(options.entryPoint)
30
+ : options.entryPoint;
31
+
32
+ describe("production bundle", () => {
33
+ let result: BuildResult;
34
+ let bundleText: string;
35
+
36
+ beforeAll(async () => {
37
+ const esbuild = await import("esbuild");
38
+
39
+ const externalizeNonGG: Plugin = {
40
+ name: 'externalize-non-gg',
41
+ setup(build) {
42
+ build.onResolve({filter: /./}, args => {
43
+ // Only externalize import statements, not entry points
44
+ if (args.kind !== 'import-statement' && args.kind !== 'dynamic-import') return null;
45
+ // Keep relative/absolute paths bundled
46
+ if (args.path.startsWith('.') || args.path.startsWith('/')) return null;
47
+ // Keep @grest-ts/* packages bundled
48
+ if (args.path.startsWith('@grest-ts/')) return null;
49
+ return {path: args.path, external: true};
50
+ });
51
+ }
52
+ };
53
+
54
+ result = await esbuild.build({
55
+ entryPoints: [entryPoint],
56
+ bundle: true,
57
+ write: false,
58
+ platform: 'node',
59
+ format: 'esm',
60
+ define: {'process.env.NODE_ENV': '"production"'},
61
+ plugins: [externalizeNonGG],
62
+ });
63
+
64
+ bundleText = result.outputFiles!.map(f => f.text).join('\n');
65
+ });
66
+
67
+ test("bundle has no errors", () => {
68
+ expect(result.errors).toHaveLength(0);
69
+ });
70
+
71
+ test("bundle is non-trivially sized", () => {
72
+ expect(bundleText.length).toBeGreaterThan(100);
73
+ });
74
+
75
+ for (const [group, symbols] of Object.entries(FORBIDDEN_SYMBOLS)) {
76
+ for (const symbol of symbols) {
77
+ test(`does not contain dev-only symbol: ${symbol} (${group})`, () => {
78
+ // Match actual definitions (var X = class, class X, function X)
79
+ // but not dead-code references like: const { X } = await null
80
+ const definitionPattern = new RegExp(
81
+ `\\b(var|let|const|class|function)\\s+${symbol}\\b`
82
+ );
83
+ expect(bundleText).not.toMatch(definitionPattern);
84
+ });
85
+ }
86
+ }
87
+ });
88
+ }
89
+ }