[snap runner] debug mode

This commit is contained in:
Mofei Zhang
2023-05-03 14:50:27 -04:00
parent 7e990419c1
commit 407e7b0c62
2 changed files with 17 additions and 3 deletions
@@ -28,9 +28,11 @@ export type TestResult = {
export async function compile(
compilerPath: string,
loggerPath: string,
fixturesDir: string,
fixture: string,
compilerVersion: number
compilerVersion: number,
isOnlyFixture: boolean
): Promise<TestResult> {
const seenConsoleErrors: Array<string> = [];
console.error = (...messages: Array<string>) => {
@@ -67,6 +69,12 @@ export async function compile(
// NOTE: we intentionally require lazily here so that we can clear the require cache
// and load fresh versions of the compiler when `compilerVersion` changes.
const { runReactForgetBabelPlugin } = require(compilerPath);
const { toggleLogging } = require(loggerPath);
// only try logging if we filtered out all but one fixture,
// since console log order is non-deterministic
const shouldLogPragma = input.split("\n")[0].includes("@debug");
toggleLogging(isOnlyFixture && shouldLogPragma);
// Extract the first line to quickly check for custom test directives
const firstLine = input.substring(0, input.indexOf("\n"));
+8 -2
View File
@@ -28,6 +28,7 @@ const COMPILER_PATH = path.join(
"Babel",
"RunReactForgetBabelPlugin.js"
);
const LOGGER_PATH = path.join(process.cwd(), "dist", "Utils", "logger.js");
const FIXTURES_PATH = path.join(
process.cwd(),
"src",
@@ -144,6 +145,7 @@ async function run(
} else {
fixtures = allFixtures;
}
const isOnlyFixture = filter !== null && fixtures.length === 1;
let entries: Array<[string, TestResult]>;
if (!opts.sync) {
@@ -152,9 +154,11 @@ async function run(
fixtures.map(async (fixture) => {
let output = await worker.compile(
COMPILER_PATH,
LOGGER_PATH,
FIXTURES_PATH,
fixture,
compilerVersion
compilerVersion,
isOnlyFixture
);
return [fixture, output];
})
@@ -164,9 +168,11 @@ async function run(
for (const fixture of fixtures) {
let output = await compiler.compile(
COMPILER_PATH,
LOGGER_PATH,
FIXTURES_PATH,
fixture,
compilerVersion
compilerVersion,
isOnlyFixture
);
entries.push([fixture, output]);
}