Skip to content

Commit 6448ff5

Browse files
committed
docs: update AGENTS.md with snapshot test workflow
1 parent 78284c2 commit 6448ff5

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

packages/plpgsql-deparser/AGENTS.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,43 @@ The round-trip test (`__tests__/plpgsql-deparser.test.ts`):
4949
3. Compares the AST from original parse with the AST from reparsed output
5050
4. Reports any failures (AST mismatches or reparse failures)
5151

52-
### Step 4: Commit Both Files
52+
### Step 4: Add Snapshot Tests (Optional but Recommended)
5353

54-
Always commit both the fixture file AND the generated.json together:
54+
For important deparser fixes, add explicit test cases with snapshots to `__tests__/deparser-fixes.test.ts`:
55+
56+
```typescript
57+
it('should handle [description]', async () => {
58+
const sql = `CREATE FUNCTION test_example(...)
59+
LANGUAGE plpgsql AS $$
60+
BEGIN
61+
-- your test case
62+
END$$`;
63+
64+
await testUtils.expectAstMatch('description', sql);
65+
66+
const parsed = parsePlPgSQLSync(sql) as unknown as PLpgSQLParseResult;
67+
const deparsed = deparseSync(parsed);
68+
expect(deparsed).toMatchSnapshot();
69+
// Add specific assertions
70+
expect(deparsed).toContain('expected output');
71+
});
72+
```
73+
74+
Then run tests with snapshot update:
75+
76+
```bash
77+
pnpm test --updateSnapshot
78+
```
79+
80+
### Step 5: Commit All Files
81+
82+
Always commit the fixture file, generated.json, test file, AND snapshots together:
5583

5684
```bash
5785
git add __fixtures__/plpgsql/plpgsql_deparser_fixes.sql
5886
git add __fixtures__/plpgsql-generated/generated.json
87+
git add packages/plpgsql-deparser/__tests__/deparser-fixes.test.ts
88+
git add packages/plpgsql-deparser/__tests__/__snapshots__/deparser-fixes.test.ts.snap
5989
git commit -m "test: add fixtures for [description]"
6090
```
6191

0 commit comments

Comments
 (0)