Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bfd35be
chore: move data_fixture_dart under packages/ and bump to Dart 3
andreadelfante May 12, 2026
d217f34
feat: add data_fixture_dart_annotations package
andreadelfante May 12, 2026
f7eaf36
feat: add generator scaffold and Jaro-Winkler similarity
andreadelfante May 12, 2026
48a7433
fix: correct similarity doc comment, SDK constraint, and test labels
andreadelfante May 12, 2026
ec15938
feat: add FakerType mapping and 3-layer field resolver
andreadelfante May 12, 2026
017c636
fix: use valid Dart null expression for unknown-type fallback in fiel…
andreadelfante May 12, 2026
af6ceef
feat: add constructor resolver
andreadelfante May 12, 2026
959cd57
fix: explicitly strip nullability from getDisplayString in non-Interf…
andreadelfante May 12, 2026
1131c87
feat: add JSON builder strategy resolver
andreadelfante May 12, 2026
e2b34ca
fix: guard against empty paramNames producing invalid Dart in json fi…
andreadelfante May 12, 2026
a0d0c85
feat: add trait code generator
andreadelfante May 12, 2026
7a22d49
fix: safe fakerTypeToCode lookup and guard against empty params in tr…
andreadelfante May 12, 2026
91bad6a
feat: add main fixture generator and update builder to LibraryBuilder
andreadelfante May 12, 2026
3e47a80
fix: simplify isJsonFactory and add type guard for fields annotation …
andreadelfante May 12, 2026
0a85b55
test(generator): wrap output matchers in decodedMatches for build_tes…
andreadelfante May 14, 2026
4e1058a
fix(generator): address code review issues
andreadelfante May 14, 2026
7eb7028
docs: add example project design spec
andreadelfante May 14, 2026
d2b8929
Revert "docs: add example project design spec"
andreadelfante May 14, 2026
25a3911
chore: ignore docs/superpowers/ from git
andreadelfante May 14, 2026
87e835a
chore: add FVM config pinned to Flutter 3.41.9 (Dart 3.11.5)
andreadelfante May 14, 2026
f1159e4
feat: add example project and fix generator for multiple @FixtureFor …
andreadelfante May 14, 2026
b652250
docs: update README and add migration guides
andreadelfante May 14, 2026
d36ac6f
feat(generator): auto-discover and generate factories for nested types
andreadelfante May 18, 2026
4bdd4d3
docs: add CLAUDE.md with project architecture and conventions
andreadelfante May 18, 2026
3263bd4
ci: migrate to Melos monorepo, fix broken CI pipeline
andreadelfante May 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutterSdkVersion": "3.41.9"
}
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.41.9"
}
23 changes: 17 additions & 6 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
name: Setup Dart environment and get dependencies
description: Installs Dart SDK 2.12.0 and runs `dart pub get` to fetch project dependencies
name: Setup Dart environment
description: Installs Dart SDK 3.7, activates Melos, and bootstraps the workspace

runs:
using: "composite"
steps:
- name: Install Dart
uses: dart-lang/setup-dart@v1.4
uses: dart-lang/setup-dart@v1
with:
sdk: 2.14.0
sdk: "3.7"

- name: Get dependencies
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}
restore-keys: ${{ runner.os }}-pub-

- name: Activate Melos
shell: bash
run: dart pub global activate melos

- name: Bootstrap workspace
shell: bash
run: dart pub get
run: melos bootstrap
6 changes: 3 additions & 3 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Dart
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
- name: Analyze
run: dart analyze
run: melos run analyze
8 changes: 6 additions & 2 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ name: Dart CI
on:
pull_request:
push:
branches:
- main
tags:
- "v*"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}

jobs:
test:
Expand All @@ -28,4 +32,4 @@ jobs:
needs:
- release
name: Publish
uses: ./.github/workflows/publish.yml
uses: ./.github/workflows/publish.yml
11 changes: 9 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ on:

jobs:
publish:
if: startsWith(github.ref, 'refs/tags/')
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
id-token: write
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
- name: Publish packages
run: melos publish --no-dry-run --yes
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:

jobs:
release:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 14 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Dart
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
- name: Run Tests
run: dart test
- name: Run tests
run: melos run test

example-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
- name: Build example
run: melos run build
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Superpowers
docs/superpowers/

# FVM
.fvm/flutter_sdk

# Miscellaneous
*.class
*.log
Expand Down
68 changes: 68 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Purpose

Test fixture library for Dart/Flutter projects. Solves the problem of creating realistic fake model instances in tests without boilerplate. Instead of hand-crafting constructors with dummy data in every test file, you define a factory once and call `makeSingle()` / `makeMany(n)` anywhere.

Core dependency is `package:faker` (re-exported), which supplies realistic random data (names, dates, companies, etc.).

### When to use which method

| Need | Method |
|---|---|
| Model instance for a test | `makeSingle()` / `makeMany(n)` |
| JSON map (e.g. to test a deserializer) | `makeJsonObject()` / `makeJsonArray(n)` |
| Both model + JSON in sync (e.g. to test round-trip serialization) | `makeSingleWithJsonObject()` / `makeManyWithJsonArray(n)` |
| JSON from already-existing model instances | `makeJsonObjectFromSingle(obj)` / `makeJsonArrayFromMany(list)` |
| Edge-case variant (different fields, empty list, etc.) | define a named method returning `redefine()` / `redefineJson()` |

## Commands

```shell
dart test # run all tests
dart test test/foo_test.dart # run single test file
dart analyze # static analysis
```

## Architecture

Pure Dart package — no Flutter dependency. Published to pub.dev as `data_fixture_dart`.

### Layer responsibilities

**Makers** (`lib/makers/`) — abstract interfaces only:
- `FixtureMaker<Model>` — `makeSingle()`, `makeMany(int)`
- `JsonFixtureMaker<Model>` extends above — adds JSON output methods

**Definitions** (`lib/definitions/`) — concrete generation logic:
- `FixtureDefinition<Model>` — holds a `FixtureDefinitionBuilder` (a `(Faker, [int index]) => Model` lambda) and a `Faker` instance; `makeMany` drives the lambda via `List.generate`, passing `index`
- `JsonFixtureDefinition<Model>` — wraps a `FixtureDefinition` + a `JsonFixtureDefinitionBuilder` (`(Model, [int index]) => Map<String, dynamic>`); JSON generation always generates the model first, then maps it to JSON

**Factories** (`lib/factories/`) — public API consumed by users:
- `FixtureFactory<Model>` — abstract; users override `definition()` returning a `FixtureDefinition`. Provides `define()` (new definition) and `redefine()` (mutate result of `definition()`) helpers
- `JsonFixtureFactory<Model>` extends `FixtureFactory` — users also override `jsonDefinition()`. Adds `defineJson()` and `redefineJson()` helpers

**Misc** (`lib/misc/`):
- `FixtureTuple<T>` — value object pairing `object` + `json`; returned by `makeSingleWithJsonObject()` / `makeManyWithJsonArray()`

### Key design rules

- `redefine()` calls `definition().definition(faker, index)` internally, then passes the result to the user's lambda — so partial overrides are cheap (just change the fields you care about).
- `redefineJson()` reuses `jsonDefinition().jsonDefinition` (the builder), so JSON shape stays the same when you only want to change the model.
- `index` is exposed to both builder lambdas so generated collections can have stable, predictable field values (e.g., sequential IDs in tests).
- Custom `Faker` instances (with seed or custom providers) can be injected via the `faker:` named parameter on `define`/`redefine`.
- The library re-exports `package:faker/faker.dart` so consumers only need one import.

### Convention for test fixtures

Factories are private (`_FooFixtureFactory`) and exposed via an extension method on the model:

```dart
extension FooFixture on Foo {
static _FooFixtureFactory factory() => _FooFixtureFactory();
}
```

Custom definitions (e.g., `empty()`, `withFields()`) return `FixtureDefinition<Model>` or `JsonFixtureDefinition<Model>` so callers can chain directly into `makeSingle()` / `makeJsonObject()` etc.
178 changes: 0 additions & 178 deletions README.md

This file was deleted.

Loading
Loading