Skip to content

Commit 104a843

Browse files
fix: async forEach bug in test framework preventing error catching
- Convert forEach to for-of loop to properly await async operations - Fix TypeScript error with diff function null handling - Add detailed logging for SQL comparison debugging - Test framework now properly catches deparser failures that generate invalid SQL Previously, errors thrown in async forEach callbacks were fire-and-forget and never bubbled up to fail tests. This meant deparser bugs generating invalid SQL went undetected. The fix enables proper error catching and detailed debugging output. Co-Authored-By: Dan Lynch <[email protected]>
1 parent 067d75e commit 104a843

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

packages/deparser/test-utils/index.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ export class TestUtils {
9595
async expectAstMatch(testName: string, sql: string) {
9696
let tree: any;
9797
try {
98-
tree = this.tryParse(sql);
98+
tree = await this.tryParse(sql);
9999
if (tree.stmts) {
100-
tree.stmts.forEach(async (stmt: any) => {
100+
for (const stmt of tree.stmts) {
101101
if (stmt.stmt) {
102102
const outSql = deparse(stmt.stmt);
103+
104+
console.log(`\n🔍 DEBUGGING SQL COMPARISON for test: ${testName}`);
105+
console.log(`📥 INPUT SQL: ${sql}`);
106+
console.log(`📤 DEPARSED SQL: ${outSql}`);
107+
console.log(`🔄 SQL MATCH: ${sql.trim() === outSql.trim() ? '✅ EXACT MATCH' : '❌ DIFFERENT'}`);
108+
103109
let reparsed;
104110
try {
105111
reparsed = await parse(outSql);
@@ -135,7 +141,7 @@ export class TestUtils {
135141
throw createParseError('AST_MISMATCH', testName, sql, outSql, originalClean, reparsedClean);
136142
}
137143
}
138-
});
144+
}
139145
}
140146
} catch (err) {
141147
const errorMessages: string[] = [];
@@ -164,7 +170,7 @@ export class TestUtils {
164170
`\nACTUAL AST:`,
165171
JSON.stringify(parseError.reparsedAst, null, 2),
166172
`\nDIFF (what's missing from actual vs expected):`,
167-
diff(parseError.originalAst, parseError.reparsedAst)
173+
diff(parseError.originalAst, parseError.reparsedAst) || 'No diff available'
168174
);
169175
} else if (parseError.originalAst) {
170176
errorMessages.push(`❌ AST: ${JSON.stringify(parseError.originalAst, null, 2)}`);
@@ -210,12 +216,16 @@ export class FixtureTestUtils extends TestUtils {
210216
console.log('no filters provided, skipping tests.');
211217
return;
212218
}
213-
this.getTestEntries(filters).forEach(async ([relativePath, sql]) => {
219+
console.log(`\n🚀 STARTING FIXTURE TESTS with filters:`, filters);
220+
const entries = this.getTestEntries(filters);
221+
for (const [relativePath, sql] of entries) {
222+
console.log(`\n📁 Processing fixture: ${relativePath}`);
223+
console.log(`📝 SQL Content: ${sql}`);
214224
try {
215225
await this.expectAstMatch(relativePath, sql);
216226
} catch (err) {
217227
throw err;
218228
}
219-
});
229+
}
220230
}
221231
}

0 commit comments

Comments
 (0)