|
7 | 7 | rmSync, |
8 | 8 | } from "fs"; |
9 | 9 | import crypto from "node:crypto"; |
| 10 | +import { readFileSync } from "node:fs"; |
10 | 11 | import { tmpdir } from "os"; |
11 | 12 | import path from "path"; |
12 | 13 | import { setTimeout } from "timers/promises"; |
@@ -323,16 +324,21 @@ export const waitForExit = async ( |
323 | 324 | }; |
324 | 325 | }; |
325 | 326 |
|
326 | | -export const createTestLogStream = ( |
| 327 | +const createTestLogStream = ( |
327 | 328 | opts: { experimental: boolean }, |
328 | 329 | task: RunnerTestCase, |
329 | 330 | ) => { |
330 | 331 | // The .ansi extension allows for editor extensions that format ansi terminal codes |
331 | 332 | const fileName = `${normalizeTestName(task)}.ansi`; |
332 | 333 | 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, { |
334 | 336 | flags: "a", |
335 | 337 | }); |
| 338 | + return { |
| 339 | + logPath, |
| 340 | + logStream, |
| 341 | + }; |
336 | 342 | }; |
337 | 343 |
|
338 | 344 | export const recreateLogFolder = ( |
@@ -374,7 +380,7 @@ const normalizeTestName = (task: Test) => { |
374 | 380 | return baseName + suffix; |
375 | 381 | }; |
376 | 382 |
|
377 | | -export const testProjectDir = (suite: string, test: string) => { |
| 383 | +const testProjectDir = (suite: string, test: string) => { |
378 | 384 | const tmpDirPath = |
379 | 385 | process.env.E2E_PROJECT_PATH ?? |
380 | 386 | realpathSync(mkdtempSync(path.join(tmpdir(), `c3-tests-${suite}`))); |
@@ -496,9 +502,21 @@ export const test = (opts: { experimental: boolean }) => |
496 | 502 | await use({ path: getPath(), name: getName() }); |
497 | 503 | clean(); |
498 | 504 | }, |
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 | + |
501 | 518 | await use(logStream); |
| 519 | + |
502 | 520 | logStream.close(); |
503 | 521 | }, |
504 | 522 | }); |
|
0 commit comments