Skip to content

Extract shared connector code into contract-case-connector-js package#1263

Open
TimothyJones wants to merge 3 commits intomainfrom
claude/add-vitest-bindings-yh8EQ
Open

Extract shared connector code into contract-case-connector-js package#1263
TimothyJones wants to merge 3 commits intomainfrom
claude/add-vitest-bindings-yh8EQ

Conversation

@TimothyJones
Copy link
Member

Summary

This PR refactors the ContractCase codebase to extract common JavaScript/TypeScript connector logic into a new shared package (@contract-case/contract-case-connector-js), reducing duplication and enabling easier support for multiple test frameworks.

Key Changes

  • New Package: Created @contract-case/contract-case-connector-js containing:

    • Core connector classes (ContractCaseDefiner, ContractVerifier)
    • DSL definitions and matchers
    • Configuration types and entities
    • Error handling and utilities
    • Previously duplicated code from Jest implementation
  • New Vitest Support: Added @contract-case/contract-case-vitest package with:

    • Vitest-specific test wrapper functions (defineContract, verifyContract)
    • Type definitions for Vitest configuration
    • Integration with Vitest's test runner and timeout handling
  • Jest Package Refactoring: Updated @contract-case/contract-case-jest to:

    • Depend on the new shared connector package
    • Re-export shared code for backward compatibility
    • Remove duplicated connector logic
    • Maintain existing Jest-specific bindings
  • Import Path Updates: Updated import statements across the codebase to use the new shared package structure and ES module syntax (.js extensions)

Implementation Details

  • Both Jest and Vitest packages now share a common foundation through contract-case-connector-js, reducing maintenance burden
  • Backward compatibility maintained through namespace re-exports (dsl, TestEquivalenceMatchers)
  • Each framework package maintains its own test runner integration while leveraging shared core functionality
  • Configuration and type definitions are centralized in the connector package

https://claude.ai/code/session_015ncC7UbQNQN3st9e3HEBNA

Extract shared (non-test-framework-specific) code from contract-case-jest
into a new contract-case-connector-js package. Both contract-case-jest and
the new contract-case-vitest package now depend on the shared connector,
keeping only their framework-specific bindings (describe/it/afterAll wrappers).

- New package: @contract-case/contract-case-connector-js
  Contains: ContractDefiner, ContractVerifier, TriggerGroupMap, DSL
  (Matchers, Interactions, States), entity types, error classes, and
  boundary mappers

- New package: @contract-case/contract-case-vitest
  Vitest-specific defineContract/verifyContract using vitest's describe/it
  and vi.setConfig for timeouts

- Updated: @contract-case/contract-case-jest
  Now re-exports from connector-js, keeping only jest-specific bindings

https://claude.ai/code/session_015ncC7UbQNQN3st9e3HEBNA
- Extract user-facing code (DSL, classes, types, errors) to new
  contract-case-dsl-js package
- Keep internal code (boundary mappers, printer, handler) in
  contract-case-connector-js
- Rename contract-case-jest to contract-case-dsl-js-jest
- Rename contract-case-vitest to contract-case-dsl-js-vitest
- Add vitest test files mirroring the jest test suite (define and
  verify specs for HTTP client/server, function caller/implementer)
- Copy test fixtures (client, server, gRPC) to vitest package
- Update vitest.config.ts to include .spec.verify.ts files

https://claude.ai/code/session_015ncC7UbQNQN3st9e3HEBNA
- Fix import ordering in dsl-js (external imports before local)
- Merge duplicate imports from connector-js in ContractDefiner/ContractVerifier
- Merge duplicate imports from index.js in jest verify specs
- Fix duplicate imports in jest documentation spec
- Add missing gRPC devDependencies to vitest package
- Apply prettier formatting fixes

https://claude.ai/code/session_015ncC7UbQNQN3st9e3HEBNA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants