@@ -49,13 +49,43 @@ The round-trip test (`__tests__/plpgsql-deparser.test.ts`):
49493 . Compares the AST from original parse with the AST from reparsed output
50504 . 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
5785git add __fixtures__/plpgsql/plpgsql_deparser_fixes.sql
5886git 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
5989git commit -m " test: add fixtures for [description]"
6090```
6191
0 commit comments