Skip to content

Commit b995680

Browse files
test: log the C3 e2e log file to the console when a test fails (#7982)
* test: log the C3 e2e log file to the console when a test fails Hopefully this will help with debugging C3 e2e tests without having to download the log artifact files.
1 parent 59c7c8e commit b995680

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

packages/create-cloudflare/e2e-tests/cli.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "./helpers";
1313
import type { Suite } from "vitest";
1414

15-
const experimental = Boolean(process.env.E2E_EXPERIMENTAL);
15+
const experimental = process.env.E2E_EXPERIMENTAL === "true";
1616
const frameworkToTest = getFrameworkToTest({ experimental: false });
1717

1818
// Note: skipIf(frameworkToTest) makes it so that all the basic C3 functionality

packages/create-cloudflare/e2e-tests/frameworks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ function getFrameworkTests(opts: {
624624
}
625625
}
626626

627-
const experimental = Boolean(process.env.E2E_EXPERIMENTAL);
627+
const experimental = process.env.E2E_EXPERIMENTAL === "true";
628628
const frameworkMap = getFrameworkMap({ experimental });
629629
const frameworkTests = getFrameworkTests({ experimental });
630630

packages/create-cloudflare/e2e-tests/helpers.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
rmSync,
88
} from "fs";
99
import crypto from "node:crypto";
10+
import { readFileSync } from "node:fs";
1011
import { tmpdir } from "os";
1112
import path from "path";
1213
import { setTimeout } from "timers/promises";
@@ -323,16 +324,21 @@ export const waitForExit = async (
323324
};
324325
};
325326

326-
export const createTestLogStream = (
327+
const createTestLogStream = (
327328
opts: { experimental: boolean },
328329
task: RunnerTestCase,
329330
) => {
330331
// The .ansi extension allows for editor extensions that format ansi terminal codes
331332
const fileName = `${normalizeTestName(task)}.ansi`;
332333
assert(task.suite, "Expected task.suite to be defined");
333-
return createWriteStream(path.join(getLogPath(opts, task.suite), fileName), {
334+
const logPath = path.join(getLogPath(opts, task.suite), fileName);
335+
const logStream = createWriteStream(logPath, {
334336
flags: "a",
335337
});
338+
return {
339+
logPath,
340+
logStream,
341+
};
336342
};
337343

338344
export const recreateLogFolder = (
@@ -374,7 +380,7 @@ const normalizeTestName = (task: Test) => {
374380
return baseName + suffix;
375381
};
376382

377-
export const testProjectDir = (suite: string, test: string) => {
383+
const testProjectDir = (suite: string, test: string) => {
378384
const tmpDirPath =
379385
process.env.E2E_PROJECT_PATH ??
380386
realpathSync(mkdtempSync(path.join(tmpdir(), `c3-tests-${suite}`)));
@@ -496,9 +502,21 @@ export const test = (opts: { experimental: boolean }) =>
496502
await use({ path: getPath(), name: getName() });
497503
clean();
498504
},
499-
async logStream({ task }, use) {
500-
const logStream = createTestLogStream(opts, task);
505+
async logStream({ task, onTestFailed }, use) {
506+
const { logPath, logStream } = createTestLogStream(opts, task);
507+
508+
onTestFailed(() => {
509+
console.error("##[group]Logs from failed test:", logPath);
510+
try {
511+
console.error(readFileSync(logPath, "utf8"));
512+
} catch {
513+
console.error("Unable to read log file");
514+
}
515+
console.error("##[endgroup]");
516+
});
517+
501518
await use(logStream);
519+
502520
logStream.close();
503521
},
504522
});

packages/create-cloudflare/e2e-tests/workers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function getWorkerTests(opts: { experimental: boolean }): WorkerTestConfig[] {
147147
}
148148
}
149149

150-
const experimental = Boolean(process.env.E2E_EXPERIMENTAL);
150+
const experimental = process.env.E2E_EXPERIMENTAL === "true";
151151
const workerTests = getWorkerTests({ experimental });
152152

153153
describe

0 commit comments

Comments
 (0)