From 4cf86028c0d6c73066dddb731b651cd07a96f290 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Mon, 24 Apr 2023 15:52:54 -0400 Subject: [PATCH] [snap tester] Patch runner for sync mode --- `yarn snap --sync` currently fails on `error.file-has-non-critical-errors`. This is because we're relying on a globally overwritten `console.error` function to report non-fatal errors. However, executing `Promise.all(...)` on a single nodejs thread will interleave calls to `run` (which is an async function). --- compiler/forget/packages/snap/src/runner.ts | 38 ++++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/compiler/forget/packages/snap/src/runner.ts b/compiler/forget/packages/snap/src/runner.ts index 7e5ce0ac4f..86b5ecd3ee 100644 --- a/compiler/forget/packages/snap/src/runner.ts +++ b/compiler/forget/packages/snap/src/runner.ts @@ -99,28 +99,32 @@ async function run(compilerVersion: number): Promise { ) ).sort(); - // Note: promise.all to ensure parallelism when enabled - const entries: Array<[string, TestResult]> = await Promise.all( - fixtures.map(async (fixture) => { - let output: TestResult; - if (PARALLEL) { - output = await worker.compile( + let entries: Array<[string, TestResult]>; + if (PARALLEL) { + // Note: promise.all to ensure parallelism when enabled + entries = await Promise.all( + fixtures.map(async (fixture) => { + let output = await worker.compile( COMPILER_PATH, FIXTURES_PATH, fixture, compilerVersion ); - } else { - output = await compiler.compile( - COMPILER_PATH, - FIXTURES_PATH, - fixture, - compilerVersion - ); - } - return [fixture, output]; - }) - ); + return [fixture, output]; + }) + ); + } else { + entries = []; + for (const fixture of fixtures) { + let output = await compiler.compile( + COMPILER_PATH, + FIXTURES_PATH, + fixture, + compilerVersion + ); + entries.push([fixture, output]); + } + } return new Map(entries); }