@contractspec/lib.testing 1.56.1 → 1.58.0
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/dist/adapters/jest-adapter.d.ts +7 -11
- package/dist/adapters/jest-adapter.d.ts.map +1 -1
- package/dist/adapters/vitest-adapter.d.ts +7 -11
- package/dist/adapters/vitest-adapter.d.ts.map +1 -1
- package/dist/generator/assertion-builder.d.ts +6 -10
- package/dist/generator/assertion-builder.d.ts.map +1 -1
- package/dist/generator/golden-test-generator.d.ts +19 -23
- package/dist/generator/golden-test-generator.d.ts.map +1 -1
- package/dist/generator/golden-test-generator.test.d.ts +2 -0
- package/dist/generator/golden-test-generator.test.d.ts.map +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +223 -6
- package/dist/node/index.js +223 -0
- package/dist/recorder/traffic-recorder.d.ts +30 -34
- package/dist/recorder/traffic-recorder.d.ts.map +1 -1
- package/dist/types.d.ts +36 -43
- package/dist/types.d.ts.map +1 -1
- package/package.json +20 -16
- package/dist/adapters/jest-adapter.js +0 -28
- package/dist/adapters/jest-adapter.js.map +0 -1
- package/dist/adapters/vitest-adapter.js +0 -27
- package/dist/adapters/vitest-adapter.js.map +0 -1
- package/dist/contracts/src/app-config/lifecycle.d.ts +0 -1
- package/dist/contracts/src/app-config/runtime.d.ts +0 -13
- package/dist/contracts/src/app-config/spec.d.ts +0 -9
- package/dist/contracts/src/app-config/validation.d.ts +0 -8
- package/dist/contracts/src/capabilities/capabilities.d.ts +0 -13
- package/dist/contracts/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/contracts/src/capabilities/context.d.ts +0 -1
- package/dist/contracts/src/capabilities/guards.d.ts +0 -4
- package/dist/contracts/src/capabilities/index.d.ts +0 -5
- package/dist/contracts/src/capabilities/openbanking.d.ts +0 -1
- package/dist/contracts/src/capabilities/validation.d.ts +0 -4
- package/dist/contracts/src/client/index.d.ts +0 -1
- package/dist/contracts/src/client/react/drivers/rn-reusables.d.ts +0 -1
- package/dist/contracts/src/client/react/drivers/shadcn.d.ts +0 -1
- package/dist/contracts/src/client/react/feature-render.d.ts +0 -3
- package/dist/contracts/src/client/react/form-render.d.ts +0 -4
- package/dist/contracts/src/client/react/index.d.ts +0 -4
- package/dist/contracts/src/contract-registry/index.d.ts +0 -2
- package/dist/contracts/src/contract-registry/schemas.d.ts +0 -2
- package/dist/contracts/src/contract-registry/types.d.ts +0 -1
- package/dist/contracts/src/data-views/index.d.ts +0 -3
- package/dist/contracts/src/data-views/registry.d.ts +0 -2
- package/dist/contracts/src/data-views/report/contractVerificationTable.d.ts +0 -1
- package/dist/contracts/src/data-views/spec.d.ts +0 -3
- package/dist/contracts/src/data-views/types.d.ts +0 -2
- package/dist/contracts/src/docs/accessibility_wcag_compliance_specs.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/capabilities/documentationSystem.capability.d.ts +0 -1
- package/dist/contracts/src/docs/capabilities/index.d.ts +0 -1
- package/dist/contracts/src/docs/commands/docsGenerate.command.d.ts +0 -2
- package/dist/contracts/src/docs/commands/docsPublish.command.d.ts +0 -2
- package/dist/contracts/src/docs/commands/index.d.ts +0 -2
- package/dist/contracts/src/docs/contracts.d.ts +0 -7
- package/dist/contracts/src/docs/events/docsGenerated.event.d.ts +0 -2
- package/dist/contracts/src/docs/events/docsPublished.event.d.ts +0 -2
- package/dist/contracts/src/docs/events/index.d.ts +0 -2
- package/dist/contracts/src/docs/forms/docsSearch.form.d.ts +0 -2
- package/dist/contracts/src/docs/forms/index.d.ts +0 -1
- package/dist/contracts/src/docs/index.d.ts +0 -33
- package/dist/contracts/src/docs/presentations/docsLayout.presentation.d.ts +0 -1
- package/dist/contracts/src/docs/presentations/docsReferencePage.presentation.d.ts +0 -1
- package/dist/contracts/src/docs/presentations/index.d.ts +0 -2
- package/dist/contracts/src/docs/presentations.d.ts +0 -2
- package/dist/contracts/src/docs/queries/contractReference.query.d.ts +0 -2
- package/dist/contracts/src/docs/queries/docsIndex.query.d.ts +0 -2
- package/dist/contracts/src/docs/queries/index.d.ts +0 -2
- package/dist/contracts/src/docs/registry.d.ts +0 -10
- package/dist/contracts/src/docs/registry.d.ts.map +0 -1
- package/dist/contracts/src/docs/tech/auth/better-auth-nextjs.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/contracts/README.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/contracts/openapi-export.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/contracts/openapi-import.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/lifecycle-stage-system.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/llm/llm-integration.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/mcp-endpoints.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/presentation-runtime.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/schema/README.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/learning-events.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/learning-journeys.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/platform-admin-panel.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/project-access-teams.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/project-routing.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/sandbox-unlogged.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/team-invitations.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/workspace-ops.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/studio/workspaces.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/telemetry-ingest.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/tech/vscode-extension.docblock.d.ts +0 -1
- package/dist/contracts/src/docs/views/contractReference.dataView.d.ts +0 -1
- package/dist/contracts/src/docs/views/docsIndex.dataView.d.ts +0 -1
- package/dist/contracts/src/docs/views/exampleCatalog.dataView.d.ts +0 -1
- package/dist/contracts/src/docs/views/index.d.ts +0 -3
- package/dist/contracts/src/events.d.ts +0 -45
- package/dist/contracts/src/events.d.ts.map +0 -1
- package/dist/contracts/src/examples/index.d.ts +0 -4
- package/dist/contracts/src/examples/registry.d.ts +0 -2
- package/dist/contracts/src/examples/schema.d.ts +0 -2
- package/dist/contracts/src/examples/types.d.ts +0 -3
- package/dist/contracts/src/examples/validation.d.ts +0 -1
- package/dist/contracts/src/experiments/evaluator.d.ts +0 -2
- package/dist/contracts/src/experiments/spec-resolver.d.ts +0 -4
- package/dist/contracts/src/experiments/spec.d.ts +0 -4
- package/dist/contracts/src/features/index.d.ts +0 -4
- package/dist/contracts/src/features/install.d.ts +0 -6
- package/dist/contracts/src/features/registry.d.ts +0 -2
- package/dist/contracts/src/features/types.d.ts +0 -5
- package/dist/contracts/src/features/validation.d.ts +0 -2
- package/dist/contracts/src/forms/forms.d.ts +0 -3
- package/dist/contracts/src/forms/index.d.ts +0 -1
- package/dist/contracts/src/index.d.ts +0 -51
- package/dist/contracts/src/install.d.ts +0 -7
- package/dist/contracts/src/integrations/connection.d.ts +0 -1
- package/dist/contracts/src/integrations/index.d.ts +0 -6
- package/dist/contracts/src/integrations/openbanking/contracts/accounts.d.ts +0 -4
- package/dist/contracts/src/integrations/openbanking/contracts/balances.d.ts +0 -4
- package/dist/contracts/src/integrations/openbanking/contracts/index.d.ts +0 -5
- package/dist/contracts/src/integrations/openbanking/contracts/transactions.d.ts +0 -4
- package/dist/contracts/src/integrations/openbanking/guards.d.ts +0 -1
- package/dist/contracts/src/integrations/openbanking/models.d.ts +0 -1
- package/dist/contracts/src/integrations/openbanking/openbanking.feature.d.ts +0 -1
- package/dist/contracts/src/integrations/operations.d.ts +0 -4
- package/dist/contracts/src/integrations/providers/elevenlabs.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/gcs-storage.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/gmail.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/google-calendar.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/index.d.ts +0 -11
- package/dist/contracts/src/integrations/providers/mistral.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/postmark.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/powens.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/qdrant.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/registry.d.ts +0 -1
- package/dist/contracts/src/integrations/providers/stripe.d.ts +0 -2
- package/dist/contracts/src/integrations/providers/twilio-sms.d.ts +0 -2
- package/dist/contracts/src/integrations/spec.d.ts +0 -3
- package/dist/contracts/src/jsonschema.d.ts +0 -4
- package/dist/contracts/src/knowledge/index.d.ts +0 -2
- package/dist/contracts/src/knowledge/operations.d.ts +0 -4
- package/dist/contracts/src/knowledge/spaces/email-threads.d.ts +0 -1
- package/dist/contracts/src/knowledge/spaces/financial-docs.d.ts +0 -1
- package/dist/contracts/src/knowledge/spaces/financial-overview.d.ts +0 -1
- package/dist/contracts/src/knowledge/spaces/index.d.ts +0 -6
- package/dist/contracts/src/knowledge/spaces/product-canon.d.ts +0 -1
- package/dist/contracts/src/knowledge/spaces/support-faq.d.ts +0 -1
- package/dist/contracts/src/knowledge/spaces/uploaded-docs.d.ts +0 -1
- package/dist/contracts/src/knowledge/spec.d.ts +0 -3
- package/dist/contracts/src/llm/exporters.d.ts +0 -7
- package/dist/contracts/src/llm/index.d.ts +0 -3
- package/dist/contracts/src/llm/prompts.d.ts +0 -2
- package/dist/contracts/src/llm/types.d.ts +0 -5
- package/dist/contracts/src/migrations.d.ts +0 -1
- package/dist/contracts/src/model-registry.d.ts +0 -1
- package/dist/contracts/src/onboarding-base.d.ts +0 -2
- package/dist/contracts/src/openapi.d.ts +0 -1
- package/dist/contracts/src/operations/index.d.ts +0 -3
- package/dist/contracts/src/operations/operation.d.ts +0 -176
- package/dist/contracts/src/operations/operation.d.ts.map +0 -1
- package/dist/contracts/src/operations/registry.d.ts +0 -6
- package/dist/contracts/src/operations/report/getContractVerificationStatus.d.ts +0 -3
- package/dist/contracts/src/operations/report/index.d.ts +0 -4
- package/dist/contracts/src/ownership.d.ts +0 -164
- package/dist/contracts/src/ownership.d.ts.map +0 -1
- package/dist/contracts/src/policy/engine.d.ts +0 -3
- package/dist/contracts/src/policy/guards.d.ts +0 -1
- package/dist/contracts/src/policy/index.d.ts +0 -6
- package/dist/contracts/src/policy/opa-adapter.d.ts +0 -3
- package/dist/contracts/src/policy/registry.d.ts +0 -2
- package/dist/contracts/src/policy/spec.d.ts +0 -13
- package/dist/contracts/src/policy/spec.d.ts.map +0 -1
- package/dist/contracts/src/policy/validation.d.ts +0 -3
- package/dist/contracts/src/presentations/index.d.ts +0 -3
- package/dist/contracts/src/presentations/presentations.d.ts +0 -3
- package/dist/contracts/src/presentations/registry.d.ts +0 -2
- package/dist/contracts/src/presentations/transform-engine.d.ts +0 -2
- package/dist/contracts/src/prompt.d.ts +0 -2
- package/dist/contracts/src/promptRegistry.d.ts +0 -2
- package/dist/contracts/src/regenerator/adapters.d.ts +0 -1
- package/dist/contracts/src/regenerator/executor.d.ts +0 -1
- package/dist/contracts/src/regenerator/index.d.ts +0 -6
- package/dist/contracts/src/regenerator/service.d.ts +0 -2
- package/dist/contracts/src/regenerator/sinks.d.ts +0 -2
- package/dist/contracts/src/regenerator/types.d.ts +0 -3
- package/dist/contracts/src/regenerator/utils.d.ts +0 -1
- package/dist/contracts/src/registry-utils.d.ts +0 -1
- package/dist/contracts/src/registry.d.ts +0 -3
- package/dist/contracts/src/resources.d.ts +0 -19
- package/dist/contracts/src/resources.d.ts.map +0 -1
- package/dist/contracts/src/schema-to-markdown.d.ts +0 -1
- package/dist/contracts/src/serialization/index.d.ts +0 -1
- package/dist/contracts/src/serialization/serializers.d.ts +0 -7
- package/dist/contracts/src/server/graphql-pothos.d.ts +0 -7
- package/dist/contracts/src/server/index.d.ts +0 -7
- package/dist/contracts/src/server/mcp/createMcpServer.d.ts +0 -5
- package/dist/contracts/src/server/mcp/mcpTypes.d.ts +0 -2
- package/dist/contracts/src/server/provider-mcp.d.ts +0 -1
- package/dist/contracts/src/server/rest-elysia.d.ts +0 -3
- package/dist/contracts/src/server/rest-express.d.ts +0 -3
- package/dist/contracts/src/server/rest-generic.d.ts +0 -2
- package/dist/contracts/src/server/rest-next-app.d.ts +0 -3
- package/dist/contracts/src/server/rest-next-pages.d.ts +0 -3
- package/dist/contracts/src/telemetry/anomaly.d.ts +0 -2
- package/dist/contracts/src/telemetry/index.d.ts +0 -3
- package/dist/contracts/src/telemetry/spec.d.ts +0 -2
- package/dist/contracts/src/telemetry/tracker.d.ts +0 -3
- package/dist/contracts/src/tests/index.d.ts +0 -2
- package/dist/contracts/src/tests/runner.d.ts +0 -3
- package/dist/contracts/src/tests/spec.d.ts +0 -13
- package/dist/contracts/src/tests/spec.d.ts.map +0 -1
- package/dist/contracts/src/themes.d.ts +0 -2
- package/dist/contracts/src/types.d.ts +0 -5
- package/dist/contracts/src/versioning/refs.d.ts +0 -47
- package/dist/contracts/src/versioning/refs.d.ts.map +0 -1
- package/dist/contracts/src/workflow/adapters/db-adapter.d.ts +0 -1
- package/dist/contracts/src/workflow/adapters/file-adapter.d.ts +0 -1
- package/dist/contracts/src/workflow/adapters/index.d.ts +0 -3
- package/dist/contracts/src/workflow/adapters/memory-store.d.ts +0 -1
- package/dist/contracts/src/workflow/context.d.ts +0 -2
- package/dist/contracts/src/workflow/index.d.ts +0 -7
- package/dist/contracts/src/workflow/overview.docblock.d.ts +0 -1
- package/dist/contracts/src/workflow/runner.d.ts +0 -5
- package/dist/contracts/src/workflow/sla-monitor.d.ts +0 -2
- package/dist/contracts/src/workflow/spec.d.ts +0 -5
- package/dist/contracts/src/workflow/state.d.ts +0 -1
- package/dist/contracts/src/workflow/validation.d.ts +0 -5
- package/dist/contracts/src/workspace-config/contractsrc-schema.d.ts +0 -1
- package/dist/contracts/src/workspace-config/index.d.ts +0 -1
- package/dist/contracts/src/workspace-config/workspace-config.docblock.d.ts +0 -1
- package/dist/generator/assertion-builder.js +0 -16
- package/dist/generator/assertion-builder.js.map +0 -1
- package/dist/generator/golden-test-generator.js +0 -87
- package/dist/generator/golden-test-generator.js.map +0 -1
- package/dist/recorder/traffic-recorder.js +0 -60
- package/dist/recorder/traffic-recorder.js.map +0 -1
- package/dist/schema/src/EnumType.d.ts +0 -36
- package/dist/schema/src/EnumType.d.ts.map +0 -1
- package/dist/schema/src/FieldType.d.ts +0 -30
- package/dist/schema/src/FieldType.d.ts.map +0 -1
- package/dist/schema/src/GraphQLSchemaType.d.ts +0 -2
- package/dist/schema/src/JsonSchemaType.d.ts +0 -2
- package/dist/schema/src/ScalarTypeEnum.d.ts +0 -1
- package/dist/schema/src/SchemaModel.d.ts +0 -70
- package/dist/schema/src/SchemaModel.d.ts.map +0 -1
- package/dist/schema/src/SchemaModelType.d.ts +0 -38
- package/dist/schema/src/SchemaModelType.d.ts.map +0 -1
- package/dist/schema/src/ZodSchemaType.d.ts +0 -2
- package/dist/schema/src/entity/defineEntity.d.ts +0 -1
- package/dist/schema/src/entity/generator.d.ts +0 -1
- package/dist/schema/src/entity/index.d.ts +0 -3
- package/dist/schema/src/entity/types.d.ts +0 -1
- package/dist/schema/src/index.d.ts +0 -9
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { GoldenTestCase } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
runnerImport: string;
|
|
8
|
-
runnerFunction: string;
|
|
1
|
+
import type { GoldenTestCase } from '../types';
|
|
2
|
+
export interface JestAdapterOptions {
|
|
3
|
+
suiteName: string;
|
|
4
|
+
cases: GoldenTestCase[];
|
|
5
|
+
runnerImport: string;
|
|
6
|
+
runnerFunction: string;
|
|
9
7
|
}
|
|
10
|
-
declare function generateJestSuite(options: JestAdapterOptions): string;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { JestAdapterOptions, generateJestSuite };
|
|
8
|
+
export declare function generateJestSuite(options: JestAdapterOptions): string;
|
|
13
9
|
//# sourceMappingURL=jest-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-adapter.d.ts","
|
|
1
|
+
{"version":3,"file":"jest-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/jest-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,UA0B5D"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { GoldenTestCase } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
runnerImport: string;
|
|
8
|
-
runnerFunction: string;
|
|
1
|
+
import type { GoldenTestCase } from '../types';
|
|
2
|
+
export interface VitestAdapterOptions {
|
|
3
|
+
suiteName: string;
|
|
4
|
+
cases: GoldenTestCase[];
|
|
5
|
+
runnerImport: string;
|
|
6
|
+
runnerFunction: string;
|
|
9
7
|
}
|
|
10
|
-
declare function generateVitestSuite(options: VitestAdapterOptions): string;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { VitestAdapterOptions, generateVitestSuite };
|
|
8
|
+
export declare function generateVitestSuite(options: VitestAdapterOptions): string;
|
|
13
9
|
//# sourceMappingURL=vitest-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest-adapter.d.ts","
|
|
1
|
+
{"version":3,"file":"vitest-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/vitest-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,UA8BhE"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { GoldenTestCase } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
runnerCall: string;
|
|
6
|
-
caseRef: string;
|
|
1
|
+
import type { GoldenTestCase } from '../types';
|
|
2
|
+
export interface AssertionContext {
|
|
3
|
+
runnerCall: string;
|
|
4
|
+
caseRef: string;
|
|
7
5
|
}
|
|
8
|
-
declare function buildAssertions(testCase: GoldenTestCase, ctx: AssertionContext): string;
|
|
9
|
-
declare function serialize(value: unknown): string;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { AssertionContext, buildAssertions, serialize };
|
|
6
|
+
export declare function buildAssertions(testCase: GoldenTestCase, ctx: AssertionContext): string;
|
|
7
|
+
export declare function serialize(value: unknown): string;
|
|
12
8
|
//# sourceMappingURL=assertion-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertion-builder.d.ts","
|
|
1
|
+
{"version":3,"file":"assertion-builder.d.ts","sourceRoot":"","sources":["../../src/generator/assertion-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,cAAc,EACxB,GAAG,EAAE,gBAAgB,UAWtB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,UAUvC"}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { GoldenTestCase, TrafficSnapshot } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
framework?: 'vitest' | 'jest';
|
|
9
|
-
serializeMetadata?: (snapshot: TrafficSnapshot) => Record<string, unknown>;
|
|
1
|
+
import type { GoldenTestCase, TrafficSnapshot } from '../types';
|
|
2
|
+
export interface GoldenTestGeneratorOptions {
|
|
3
|
+
suiteName: string;
|
|
4
|
+
runnerImport: string;
|
|
5
|
+
runnerFunction: string;
|
|
6
|
+
framework?: 'vitest' | 'jest';
|
|
7
|
+
serializeMetadata?: (snapshot: TrafficSnapshot) => Record<string, unknown>;
|
|
10
8
|
}
|
|
11
|
-
declare class GoldenTestGenerator {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export declare class GoldenTestGenerator {
|
|
10
|
+
private readonly serializeMetadata;
|
|
11
|
+
constructor(serializeMetadata?: GoldenTestGeneratorOptions['serializeMetadata']);
|
|
12
|
+
createCases(snapshots: TrafficSnapshot[]): GoldenTestCase[];
|
|
13
|
+
generate(snapshots: TrafficSnapshot[], options: GoldenTestGeneratorOptions): string;
|
|
16
14
|
}
|
|
17
|
-
type GoldenTestRunner = (input: unknown, metadata?: Record<string, unknown>) => Promise<unknown>;
|
|
18
|
-
interface GoldenTestRunResult {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
export type GoldenTestRunner = (input: unknown, metadata?: Record<string, unknown>) => Promise<unknown>;
|
|
16
|
+
export interface GoldenTestRunResult {
|
|
17
|
+
caseId: string;
|
|
18
|
+
passed: boolean;
|
|
19
|
+
durationMs: number;
|
|
20
|
+
error?: unknown;
|
|
23
21
|
}
|
|
24
|
-
declare function runGoldenTests(cases: GoldenTestCase[], runner: GoldenTestRunner): Promise<GoldenTestRunResult[]>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { GoldenTestGenerator, GoldenTestGeneratorOptions, GoldenTestRunResult, GoldenTestRunner, runGoldenTests };
|
|
22
|
+
export declare function runGoldenTests(cases: GoldenTestCase[], runner: GoldenTestRunner): Promise<GoldenTestRunResult[]>;
|
|
27
23
|
//# sourceMappingURL=golden-test-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"golden-test-generator.d.ts","
|
|
1
|
+
{"version":3,"file":"golden-test-generator.d.ts","sourceRoot":"","sources":["../../src/generator/golden-test-generator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhE,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5E;AAED,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;gBAAjB,iBAAiB,GAAE,0BAA0B,CAAC,mBAAmB,CAOnD;IAGjC,WAAW,CAAC,SAAS,EAAE,eAAe,EAAE,GAAG,cAAc,EAAE;IAc3D,QAAQ,CACN,SAAS,EAAE,eAAe,EAAE,EAC5B,OAAO,EAAE,0BAA0B,GAClC,MAAM;CAiBV;AAED,MAAM,MAAM,gBAAgB,GAAG,CAC7B,KAAK,EAAE,OAAO,EACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,cAAc,CAClC,KAAK,EAAE,cAAc,EAAE,EACvB,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAoChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"golden-test-generator.test.d.ts","sourceRoot":"","sources":["../../src/generator/golden-test-generator.test.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './recorder/traffic-recorder';
|
|
3
|
+
export * from './generator/golden-test-generator';
|
|
4
|
+
export * from './generator/assertion-builder';
|
|
5
|
+
export * from './adapters/vitest-adapter';
|
|
6
|
+
export * from './adapters/jest-adapter';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,224 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { generateJestSuite } from "./adapters/jest-adapter.js";
|
|
5
|
-
import { GoldenTestGenerator, runGoldenTests } from "./generator/golden-test-generator.js";
|
|
1
|
+
// @bun
|
|
2
|
+
// src/recorder/traffic-recorder.ts
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
class InMemoryTrafficStore {
|
|
6
|
+
items = [];
|
|
7
|
+
async save(snapshot) {
|
|
8
|
+
this.items.push(snapshot);
|
|
9
|
+
}
|
|
10
|
+
async list(operation) {
|
|
11
|
+
if (!operation)
|
|
12
|
+
return [...this.items];
|
|
13
|
+
return this.items.filter((item) => item.operation.name === operation);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class TrafficRecorder {
|
|
18
|
+
store;
|
|
19
|
+
sampleRate;
|
|
20
|
+
sanitize;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.store = options.store;
|
|
23
|
+
this.sampleRate = options.sampleRate ?? 1;
|
|
24
|
+
this.sanitize = options.sanitize;
|
|
25
|
+
}
|
|
26
|
+
async record(input) {
|
|
27
|
+
if (!this.shouldSample())
|
|
28
|
+
return;
|
|
29
|
+
const snapshot = {
|
|
30
|
+
id: randomUUID(),
|
|
31
|
+
operation: input.operation,
|
|
32
|
+
input: structuredCloneSafe(input.input),
|
|
33
|
+
output: structuredCloneSafe(input.output),
|
|
34
|
+
error: input.error ? structuredCloneSafe(input.error) : undefined,
|
|
35
|
+
success: input.success,
|
|
36
|
+
timestamp: new Date,
|
|
37
|
+
durationMs: input.durationMs,
|
|
38
|
+
tenantId: input.tenantId,
|
|
39
|
+
userId: input.userId,
|
|
40
|
+
channel: input.channel,
|
|
41
|
+
metadata: input.metadata
|
|
42
|
+
};
|
|
43
|
+
const sanitized = this.sanitize ? this.sanitize(snapshot) : snapshot;
|
|
44
|
+
await this.store.save(sanitized);
|
|
45
|
+
}
|
|
46
|
+
shouldSample() {
|
|
47
|
+
if (this.sampleRate >= 1)
|
|
48
|
+
return true;
|
|
49
|
+
return Math.random() <= this.sampleRate;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function structuredCloneSafe(value) {
|
|
53
|
+
if (value == null)
|
|
54
|
+
return value ?? undefined;
|
|
55
|
+
try {
|
|
56
|
+
const clone = globalThis.structuredClone;
|
|
57
|
+
if (typeof clone === "function") {
|
|
58
|
+
return clone(value);
|
|
59
|
+
}
|
|
60
|
+
return JSON.parse(JSON.stringify(value));
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// src/generator/golden-test-generator.ts
|
|
66
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
67
|
+
import { performance } from "perf_hooks";
|
|
68
|
+
|
|
69
|
+
// src/generator/assertion-builder.ts
|
|
70
|
+
function buildAssertions(testCase, ctx) {
|
|
71
|
+
if (testCase.success) {
|
|
72
|
+
return [
|
|
73
|
+
`const result = await ${ctx.runnerCall};`,
|
|
74
|
+
`expect(result).toEqual(${serialize(testCase.expectedOutput ?? null)});`
|
|
75
|
+
].join(`
|
|
76
|
+
`);
|
|
77
|
+
}
|
|
78
|
+
return `await expect(${ctx.runnerCall}).rejects.toMatchObject(${serialize(testCase.expectedError ?? { message: "expected failure" })});`;
|
|
79
|
+
}
|
|
80
|
+
function serialize(value) {
|
|
81
|
+
return JSON.stringify(value, (_key, val) => {
|
|
82
|
+
if (val instanceof Date)
|
|
83
|
+
return val.toISOString();
|
|
84
|
+
if (typeof val === "undefined")
|
|
85
|
+
return null;
|
|
86
|
+
return val;
|
|
87
|
+
}, 2);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/adapters/vitest-adapter.ts
|
|
91
|
+
function generateVitestSuite(options) {
|
|
92
|
+
const caseBlocks = options.cases.map((testCase) => {
|
|
93
|
+
const inputConst = serialize(testCase.input);
|
|
94
|
+
const metadataConst = serialize(testCase.metadata ?? {});
|
|
95
|
+
const assertions = testCase.success ? [
|
|
96
|
+
`const result = await ${options.runnerFunction}(input${testCase.id}, metadata${testCase.id});`,
|
|
97
|
+
`expect(result).toEqual(${serialize(testCase.expectedOutput ?? null)});`
|
|
98
|
+
] : [
|
|
99
|
+
`await expect(${options.runnerFunction}(input${testCase.id}, metadata${testCase.id})).rejects.toMatchObject(${serialize(testCase.expectedError ?? { message: "expected failure" })});`
|
|
100
|
+
];
|
|
101
|
+
return `
|
|
102
|
+
it('${testCase.name}', async () => {
|
|
103
|
+
const input${testCase.id} = ${inputConst};
|
|
104
|
+
const metadata${testCase.id} = ${metadataConst};
|
|
105
|
+
${assertions.join(`
|
|
106
|
+
`)}
|
|
107
|
+
});`;
|
|
108
|
+
}).join(`
|
|
109
|
+
`);
|
|
110
|
+
return `
|
|
111
|
+
import { describe, it, expect } from 'bun:test';
|
|
112
|
+
import { ${options.runnerFunction} } from '${options.runnerImport}';
|
|
113
|
+
|
|
114
|
+
describe('${options.suiteName}', () => {${caseBlocks}
|
|
115
|
+
});
|
|
116
|
+
`.trim();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/adapters/jest-adapter.ts
|
|
120
|
+
function generateJestSuite(options) {
|
|
121
|
+
const caseBlocks = options.cases.map((testCase) => {
|
|
122
|
+
const inputConst = serialize(testCase.input);
|
|
123
|
+
const metadataConst = serialize(testCase.metadata ?? {});
|
|
124
|
+
const successBlock = `const result = await ${options.runnerFunction}(input${testCase.id}, metadata${testCase.id});
|
|
125
|
+
expect(result).toEqual(${serialize(testCase.expectedOutput ?? null)});`;
|
|
126
|
+
const failureBlock = `await expect(${options.runnerFunction}(input${testCase.id}, metadata${testCase.id})).rejects.toMatchObject(${serialize(testCase.expectedError ?? { message: "expected failure" })});`;
|
|
127
|
+
return `
|
|
128
|
+
test('${testCase.name}', async () => {
|
|
129
|
+
const input${testCase.id} = ${inputConst};
|
|
130
|
+
const metadata${testCase.id} = ${metadataConst};
|
|
131
|
+
${testCase.success ? successBlock : failureBlock}
|
|
132
|
+
});`;
|
|
133
|
+
}).join(`
|
|
134
|
+
`);
|
|
135
|
+
return `
|
|
136
|
+
import { ${options.runnerFunction} } from '${options.runnerImport}';
|
|
137
|
+
|
|
138
|
+
describe('${options.suiteName}', () => {${caseBlocks}
|
|
139
|
+
});
|
|
140
|
+
`.trim();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/generator/golden-test-generator.ts
|
|
144
|
+
class GoldenTestGenerator {
|
|
145
|
+
serializeMetadata;
|
|
146
|
+
constructor(serializeMetadata = (snapshot) => ({
|
|
147
|
+
tenantId: snapshot.tenantId,
|
|
148
|
+
userId: snapshot.userId,
|
|
149
|
+
channel: snapshot.channel
|
|
150
|
+
})) {
|
|
151
|
+
this.serializeMetadata = serializeMetadata;
|
|
152
|
+
}
|
|
153
|
+
createCases(snapshots) {
|
|
154
|
+
return snapshots.map((snapshot, index) => ({
|
|
155
|
+
id: snapshot.id ?? randomUUID2(),
|
|
156
|
+
name: snapshot.success ? `case-${index + 1}-success` : `case-${index + 1}-failure`,
|
|
157
|
+
input: snapshot.input,
|
|
158
|
+
expectedOutput: snapshot.output,
|
|
159
|
+
expectedError: snapshot.error,
|
|
160
|
+
success: snapshot.success,
|
|
161
|
+
metadata: this.serializeMetadata?.(snapshot)
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
generate(snapshots, options) {
|
|
165
|
+
const cases = this.createCases(snapshots);
|
|
166
|
+
if (options.framework === "jest") {
|
|
167
|
+
return generateJestSuite({
|
|
168
|
+
suiteName: options.suiteName,
|
|
169
|
+
cases,
|
|
170
|
+
runnerImport: options.runnerImport,
|
|
171
|
+
runnerFunction: options.runnerFunction
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return generateVitestSuite({
|
|
175
|
+
suiteName: options.suiteName,
|
|
176
|
+
cases,
|
|
177
|
+
runnerImport: options.runnerImport,
|
|
178
|
+
runnerFunction: options.runnerFunction
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function runGoldenTests(cases, runner) {
|
|
183
|
+
const results = [];
|
|
184
|
+
for (const testCase of cases) {
|
|
185
|
+
const startedAt = performance.now();
|
|
186
|
+
try {
|
|
187
|
+
const output = await runner(testCase.input, testCase.metadata);
|
|
188
|
+
if (!testCase.success) {
|
|
189
|
+
results.push({
|
|
190
|
+
caseId: testCase.id,
|
|
191
|
+
passed: false,
|
|
192
|
+
durationMs: performance.now() - startedAt,
|
|
193
|
+
error: new Error("Expected failure but runner resolved")
|
|
194
|
+
});
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const matches = JSON.stringify(output) === JSON.stringify(testCase.expectedOutput ?? null);
|
|
198
|
+
results.push({
|
|
199
|
+
caseId: testCase.id,
|
|
200
|
+
passed: matches,
|
|
201
|
+
durationMs: performance.now() - startedAt,
|
|
202
|
+
error: matches ? undefined : { expected: testCase.expectedOutput, received: output }
|
|
203
|
+
});
|
|
204
|
+
} catch (error) {
|
|
205
|
+
const durationMs = performance.now() - startedAt;
|
|
206
|
+
if (!testCase.success) {
|
|
207
|
+
results.push({ caseId: testCase.id, passed: true, durationMs });
|
|
208
|
+
} else {
|
|
209
|
+
results.push({ caseId: testCase.id, passed: false, durationMs, error });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return results;
|
|
214
|
+
}
|
|
215
|
+
export {
|
|
216
|
+
serialize,
|
|
217
|
+
runGoldenTests,
|
|
218
|
+
generateVitestSuite,
|
|
219
|
+
generateJestSuite,
|
|
220
|
+
buildAssertions,
|
|
221
|
+
TrafficRecorder,
|
|
222
|
+
InMemoryTrafficStore,
|
|
223
|
+
GoldenTestGenerator
|
|
224
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// src/recorder/traffic-recorder.ts
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
class InMemoryTrafficStore {
|
|
5
|
+
items = [];
|
|
6
|
+
async save(snapshot) {
|
|
7
|
+
this.items.push(snapshot);
|
|
8
|
+
}
|
|
9
|
+
async list(operation) {
|
|
10
|
+
if (!operation)
|
|
11
|
+
return [...this.items];
|
|
12
|
+
return this.items.filter((item) => item.operation.name === operation);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class TrafficRecorder {
|
|
17
|
+
store;
|
|
18
|
+
sampleRate;
|
|
19
|
+
sanitize;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.store = options.store;
|
|
22
|
+
this.sampleRate = options.sampleRate ?? 1;
|
|
23
|
+
this.sanitize = options.sanitize;
|
|
24
|
+
}
|
|
25
|
+
async record(input) {
|
|
26
|
+
if (!this.shouldSample())
|
|
27
|
+
return;
|
|
28
|
+
const snapshot = {
|
|
29
|
+
id: randomUUID(),
|
|
30
|
+
operation: input.operation,
|
|
31
|
+
input: structuredCloneSafe(input.input),
|
|
32
|
+
output: structuredCloneSafe(input.output),
|
|
33
|
+
error: input.error ? structuredCloneSafe(input.error) : undefined,
|
|
34
|
+
success: input.success,
|
|
35
|
+
timestamp: new Date,
|
|
36
|
+
durationMs: input.durationMs,
|
|
37
|
+
tenantId: input.tenantId,
|
|
38
|
+
userId: input.userId,
|
|
39
|
+
channel: input.channel,
|
|
40
|
+
metadata: input.metadata
|
|
41
|
+
};
|
|
42
|
+
const sanitized = this.sanitize ? this.sanitize(snapshot) : snapshot;
|
|
43
|
+
await this.store.save(sanitized);
|
|
44
|
+
}
|
|
45
|
+
shouldSample() {
|
|
46
|
+
if (this.sampleRate >= 1)
|
|
47
|
+
return true;
|
|
48
|
+
return Math.random() <= this.sampleRate;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function structuredCloneSafe(value) {
|
|
52
|
+
if (value == null)
|
|
53
|
+
return value ?? undefined;
|
|
54
|
+
try {
|
|
55
|
+
const clone = globalThis.structuredClone;
|
|
56
|
+
if (typeof clone === "function") {
|
|
57
|
+
return clone(value);
|
|
58
|
+
}
|
|
59
|
+
return JSON.parse(JSON.stringify(value));
|
|
60
|
+
} catch {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// src/generator/golden-test-generator.ts
|
|
65
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
66
|
+
import { performance } from "node:perf_hooks";
|
|
67
|
+
|
|
68
|
+
// src/generator/assertion-builder.ts
|
|
69
|
+
function buildAssertions(testCase, ctx) {
|
|
70
|
+
if (testCase.success) {
|
|
71
|
+
return [
|
|
72
|
+
`const result = await ${ctx.runnerCall};`,
|
|
73
|
+
`expect(result).toEqual(${serialize(testCase.expectedOutput ?? null)});`
|
|
74
|
+
].join(`
|
|
75
|
+
`);
|
|
76
|
+
}
|
|
77
|
+
return `await expect(${ctx.runnerCall}).rejects.toMatchObject(${serialize(testCase.expectedError ?? { message: "expected failure" })});`;
|
|
78
|
+
}
|
|
79
|
+
function serialize(value) {
|
|
80
|
+
return JSON.stringify(value, (_key, val) => {
|
|
81
|
+
if (val instanceof Date)
|
|
82
|
+
return val.toISOString();
|
|
83
|
+
if (typeof val === "undefined")
|
|
84
|
+
return null;
|
|
85
|
+
return val;
|
|
86
|
+
}, 2);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/adapters/vitest-adapter.ts
|
|
90
|
+
function generateVitestSuite(options) {
|
|
91
|
+
const caseBlocks = options.cases.map((testCase) => {
|
|
92
|
+
const inputConst = serialize(testCase.input);
|
|
93
|
+
const metadataConst = serialize(testCase.metadata ?? {});
|
|
94
|
+
const assertions = testCase.success ? [
|
|
95
|
+
`const result = await ${options.runnerFunction}(input${testCase.id}, metadata${testCase.id});`,
|
|
96
|
+
`expect(result).toEqual(${serialize(testCase.expectedOutput ?? null)});`
|
|
97
|
+
] : [
|
|
98
|
+
`await expect(${options.runnerFunction}(input${testCase.id}, metadata${testCase.id})).rejects.toMatchObject(${serialize(testCase.expectedError ?? { message: "expected failure" })});`
|
|
99
|
+
];
|
|
100
|
+
return `
|
|
101
|
+
it('${testCase.name}', async () => {
|
|
102
|
+
const input${testCase.id} = ${inputConst};
|
|
103
|
+
const metadata${testCase.id} = ${metadataConst};
|
|
104
|
+
${assertions.join(`
|
|
105
|
+
`)}
|
|
106
|
+
});`;
|
|
107
|
+
}).join(`
|
|
108
|
+
`);
|
|
109
|
+
return `
|
|
110
|
+
import { describe, it, expect } from 'bun:test';
|
|
111
|
+
import { ${options.runnerFunction} } from '${options.runnerImport}';
|
|
112
|
+
|
|
113
|
+
describe('${options.suiteName}', () => {${caseBlocks}
|
|
114
|
+
});
|
|
115
|
+
`.trim();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/adapters/jest-adapter.ts
|
|
119
|
+
function generateJestSuite(options) {
|
|
120
|
+
const caseBlocks = options.cases.map((testCase) => {
|
|
121
|
+
const inputConst = serialize(testCase.input);
|
|
122
|
+
const metadataConst = serialize(testCase.metadata ?? {});
|
|
123
|
+
const successBlock = `const result = await ${options.runnerFunction}(input${testCase.id}, metadata${testCase.id});
|
|
124
|
+
expect(result).toEqual(${serialize(testCase.expectedOutput ?? null)});`;
|
|
125
|
+
const failureBlock = `await expect(${options.runnerFunction}(input${testCase.id}, metadata${testCase.id})).rejects.toMatchObject(${serialize(testCase.expectedError ?? { message: "expected failure" })});`;
|
|
126
|
+
return `
|
|
127
|
+
test('${testCase.name}', async () => {
|
|
128
|
+
const input${testCase.id} = ${inputConst};
|
|
129
|
+
const metadata${testCase.id} = ${metadataConst};
|
|
130
|
+
${testCase.success ? successBlock : failureBlock}
|
|
131
|
+
});`;
|
|
132
|
+
}).join(`
|
|
133
|
+
`);
|
|
134
|
+
return `
|
|
135
|
+
import { ${options.runnerFunction} } from '${options.runnerImport}';
|
|
136
|
+
|
|
137
|
+
describe('${options.suiteName}', () => {${caseBlocks}
|
|
138
|
+
});
|
|
139
|
+
`.trim();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/generator/golden-test-generator.ts
|
|
143
|
+
class GoldenTestGenerator {
|
|
144
|
+
serializeMetadata;
|
|
145
|
+
constructor(serializeMetadata = (snapshot) => ({
|
|
146
|
+
tenantId: snapshot.tenantId,
|
|
147
|
+
userId: snapshot.userId,
|
|
148
|
+
channel: snapshot.channel
|
|
149
|
+
})) {
|
|
150
|
+
this.serializeMetadata = serializeMetadata;
|
|
151
|
+
}
|
|
152
|
+
createCases(snapshots) {
|
|
153
|
+
return snapshots.map((snapshot, index) => ({
|
|
154
|
+
id: snapshot.id ?? randomUUID2(),
|
|
155
|
+
name: snapshot.success ? `case-${index + 1}-success` : `case-${index + 1}-failure`,
|
|
156
|
+
input: snapshot.input,
|
|
157
|
+
expectedOutput: snapshot.output,
|
|
158
|
+
expectedError: snapshot.error,
|
|
159
|
+
success: snapshot.success,
|
|
160
|
+
metadata: this.serializeMetadata?.(snapshot)
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
generate(snapshots, options) {
|
|
164
|
+
const cases = this.createCases(snapshots);
|
|
165
|
+
if (options.framework === "jest") {
|
|
166
|
+
return generateJestSuite({
|
|
167
|
+
suiteName: options.suiteName,
|
|
168
|
+
cases,
|
|
169
|
+
runnerImport: options.runnerImport,
|
|
170
|
+
runnerFunction: options.runnerFunction
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return generateVitestSuite({
|
|
174
|
+
suiteName: options.suiteName,
|
|
175
|
+
cases,
|
|
176
|
+
runnerImport: options.runnerImport,
|
|
177
|
+
runnerFunction: options.runnerFunction
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function runGoldenTests(cases, runner) {
|
|
182
|
+
const results = [];
|
|
183
|
+
for (const testCase of cases) {
|
|
184
|
+
const startedAt = performance.now();
|
|
185
|
+
try {
|
|
186
|
+
const output = await runner(testCase.input, testCase.metadata);
|
|
187
|
+
if (!testCase.success) {
|
|
188
|
+
results.push({
|
|
189
|
+
caseId: testCase.id,
|
|
190
|
+
passed: false,
|
|
191
|
+
durationMs: performance.now() - startedAt,
|
|
192
|
+
error: new Error("Expected failure but runner resolved")
|
|
193
|
+
});
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const matches = JSON.stringify(output) === JSON.stringify(testCase.expectedOutput ?? null);
|
|
197
|
+
results.push({
|
|
198
|
+
caseId: testCase.id,
|
|
199
|
+
passed: matches,
|
|
200
|
+
durationMs: performance.now() - startedAt,
|
|
201
|
+
error: matches ? undefined : { expected: testCase.expectedOutput, received: output }
|
|
202
|
+
});
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const durationMs = performance.now() - startedAt;
|
|
205
|
+
if (!testCase.success) {
|
|
206
|
+
results.push({ caseId: testCase.id, passed: true, durationMs });
|
|
207
|
+
} else {
|
|
208
|
+
results.push({ caseId: testCase.id, passed: false, durationMs, error });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return results;
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
serialize,
|
|
216
|
+
runGoldenTests,
|
|
217
|
+
generateVitestSuite,
|
|
218
|
+
generateJestSuite,
|
|
219
|
+
buildAssertions,
|
|
220
|
+
TrafficRecorder,
|
|
221
|
+
InMemoryTrafficStore,
|
|
222
|
+
GoldenTestGenerator
|
|
223
|
+
};
|