@samitouri / QOS-React-2 / commits / 407e7b0c62

[snap runner] debug mode

Mofei Zhang committed May 3, 2023 at 14:50 UTC 407e7b0c620d1bb20ce52ccaa8e8ae555ab3edc4
2 files changed +17 -3
compiler/forget/packages/snap/src/compiler-worker.ts
+9 -1
@@ -28,9 +28,11 @@ export type TestResult = {
28
29 export async function compile(
30 compilerPath: string,
31 + loggerPath: string,
32 fixturesDir: string,
33 fixture: string,
33 - compilerVersion: number
34 + compilerVersion: number,
35 + isOnlyFixture: boolean
36 ): Promise<TestResult> {
37 const seenConsoleErrors: Array<string> = [];
38 console.error = (...messages: Array<string>) => {
@@ -67,6 +69,12 @@ export async function compile(
69 // NOTE: we intentionally require lazily here so that we can clear the require cache
70 // and load fresh versions of the compiler when `compilerVersion` changes.
71 const { runReactForgetBabelPlugin } = require(compilerPath);
72 + const { toggleLogging } = require(loggerPath);
73 +
74 + // only try logging if we filtered out all but one fixture,
75 + // since console log order is non-deterministic
76 + const shouldLogPragma = input.split("\n")[0].includes("@debug");
77 + toggleLogging(isOnlyFixture && shouldLogPragma);
78
79 // Extract the first line to quickly check for custom test directives
80 const firstLine = input.substring(0, input.indexOf("\n"));
compiler/forget/packages/snap/src/runner.ts
+8 -2
@@ -28,6 +28,7 @@ const COMPILER_PATH = path.join(
28 "Babel",
29 "RunReactForgetBabelPlugin.js"
30 );
31 +const LOGGER_PATH = path.join(process.cwd(), "dist", "Utils", "logger.js");
32 const FIXTURES_PATH = path.join(
33 process.cwd(),
34 "src",
@@ -144,6 +145,7 @@ async function run(
145 } else {
146 fixtures = allFixtures;
147 }
148 + const isOnlyFixture = filter !== null && fixtures.length === 1;
149
150 let entries: Array<[string, TestResult]>;
151 if (!opts.sync) {
@@ -152,9 +154,11 @@ async function run(
154 fixtures.map(async (fixture) => {
155 let output = await worker.compile(
156 COMPILER_PATH,
157 + LOGGER_PATH,
158 FIXTURES_PATH,
159 fixture,
157 - compilerVersion
160 + compilerVersion,
161 + isOnlyFixture
162 );
163 return [fixture, output];
164 })
@@ -164,9 +168,11 @@ async function run(
168 for (const fixture of fixtures) {
169 let output = await compiler.compile(
170 COMPILER_PATH,
171 + LOGGER_PATH,
172 FIXTURES_PATH,
173 fixture,
169 - compilerVersion
174 + compilerVersion,
175 + isOnlyFixture
176 );
177 entries.push([fixture, output]);
178 }