Skip to content

[Testing] Add automated tests for the generator, catch silent template breakage from schema changes #8

@Arjun544

Description

@Arjun544

Overview

Currently there are no automated tests for the generator logic. A schema
change in app/lib/config/schema.ts can silently break template output
with no warning until someone manually runs the dev loop and notices.

This issue adds a test suite that validates the generator produces correct,
expected output for every schema configuration, catching breakage before
it reaches main.


What Should Be Tested

1. Schema Validation Tests

  • Every field in the schema has a valid default value
  • Invalid config values are rejected with a clear error
  • Adding a new field without a default fails loudly, not silently

2. Generator Output Tests

  • For each architecture (Clean, MVVM, Feature-First), the generator
    produces the expected folder structure
  • Expected files exist in the output (no missing files)
  • No unexpected files are generated
  • File contents match snapshots for critical files
    (e.g. main.dart, pubspec.yaml, router.dart)

3. Flag Combination Tests

  • Each state management option (Riverpod, Bloc, Provider) generates
    the correct dependencies in pubspec.yaml
  • Each routing option (GoRouter, AutoRoute) generates the correct
    router file
  • Flags that depend on each other compose correctly
  • Flags that conflict with each other are handled gracefully

4. Regression Tests

  • A test is added for every bug fixed in the generator
  • Schema changes that remove or rename a field fail existing tests
    immediately

Implementation

Test Runner

The project already uses Vitest (vitest.config.ts exists). Add tests
under the existing tests/ directory.

Snapshot Testing

Use Vitest snapshot testing for generated file contents. This way any
unintentional output change is caught automatically and must be explicitly
approved before merging.

Test Structure

tests/
├── schema/
│ ├── validation.test.ts ← schema field and default tests
│ └── conflicts.test.ts ← incompatible flag combinations
├── generator/
│ ├── output-structure.test.ts ← folder and file existence
│ ├── snapshots/ ← Vitest snapshots of critical files
│ └── flag-combinations.test.ts
└── regression/
└── (one file per bug fixed)


Acceptance Criteria

  • bun test runs the full suite with zero manual steps
  • Tests cover all three architectures
  • Snapshot tests exist for at least main.dart, pubspec.yaml, router.dart
  • CI workflow (see CI issue) runs bun test before dart analyze
  • A schema change that breaks output causes at least one test to fail

Notes

  • Tests should run fast, mock the file system where possible rather than
    writing to disk
  • Snapshot updates should be intentional: contributors must run
    bun test --update-snapshots explicitly and include the updated
    snapshots in their PR

References

  • tests/
  • vitest.config.ts
  • app/lib/config/schema.ts
  • scripts/template-dev.ts
  • docs/template-development.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomerstestingRelated to automated tests and test coverage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions