Skip to content

Conversation

kantord
Copy link
Member

@kantord kantord commented Sep 15, 2025

a little refactor I did yesterday for the auto mocking system. What it includes:

  • type checking even for auto-generated fixtures. This means that you get appropriate type failures for the mocks when BE introduces changes to the schema and you don't need to rely on test failures to know that you need to update a fixture.
  • improve the folder structure for fixtures

Old folder structure

Screenshot_select-area_20250916111808

New folder structure

Screenshot_select-area_20250916111351

Type checkable automatic mocks

Example:

import type { GetApiV1BetaGroupsResponse } from '@api/types.gen'

export default {
  groups: [
    { name: 'default', registered_clients: ['client-a'] },
    { name: 'Research team', registered_clients: ['client-b'] },
    { name: 'Archive', registered_clients: [] },
  ],
} satisfies GetApiV1BetaGroupsResponse

@kantord kantord changed the title Mocker path changes test: implement type-checked test fixtures Sep 15, 2025
@kantord kantord marked this pull request as ready for review September 16, 2025 10:22
@Copilot Copilot AI review requested due to automatic review settings September 16, 2025 10:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors the mocking system to implement type-checked test fixtures by converting JSON fixtures to TypeScript modules with type imports and satisfies clauses. This ensures compile-time validation of mock data against OpenAPI-generated types.

  • Converted auto-generated fixtures from JSON to TypeScript format with type checking
  • Improved fixture folder structure with shorter path names and nested directories
  • Updated mock generation logic to create type-safe fixtures with proper imports

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
use-mutation-restart-server.test.ts Enhanced test with proper async handling and query client state validation
mocker.ts Core refactor to generate TypeScript fixtures with type checking and improved file organization
mockTemplate.ts New utility to generate TypeScript module templates with conditional type imports
Various fixture files Converted from JSON to TypeScript format with type imports and satisfies clauses
customHandlers/index.ts Removed redundant handlers now covered by auto-generated fixtures
fixtures/README.md Updated documentation to reflect TypeScript fixture format

@kantord kantord enabled auto-merge (squash) September 16, 2025 11:11
@kantord kantord merged commit 88e19e7 into main Sep 16, 2025
20 checks passed
@kantord kantord deleted the mocker-path-changes branch September 16, 2025 11:17
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