From c19c522744ca4fb21ad212bea7905d058c8640ef Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Mon, 1 May 2023 09:01:41 -0700 Subject: [PATCH] Fix error links in markdown summary --- .github/scripts/test-runner.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/scripts/test-runner.ts b/.github/scripts/test-runner.ts index 946e2315b3..cd049e8227 100644 --- a/.github/scripts/test-runner.ts +++ b/.github/scripts/test-runner.ts @@ -1,6 +1,8 @@ -// Dear reader +// This file parses the output of `bun test` and outputs +// a markdown summary and Github Action annotations. // -// The existence of this file is temporary, a hack. +// In the future, a version of this will be built-in to Bun. + import { join, basename } from "node:path"; import { readdirSync, writeSync, fsyncSync, appendFileSync } from "node:fs"; import { spawn, spawnSync } from "node:child_process"; @@ -557,18 +559,17 @@ function formatTest(result: ParseTestResult, options?: FormatTestOptions): strin ...tests .filter(({ status }) => status === "fail") .map(({ name, errors }) => { - let content = header(3, name); - let hasLink = false; + let url = ""; + let content = ""; if (errors) { content += errors .map(({ name, message, stack }) => { let preview = code(`${name}: ${message}`, "diff"); if (stack?.length && baseUrl) { const { file, line } = stack[0]; - if (!is3rdParty(file) && !hasLink) { + if (!is3rdParty(file) && !url) { const { href } = new URL(`${file}?plain=1#L${line}`, baseUrl); - content = link(content, href); - hasLink = true; + url = href; } } return preview; @@ -577,7 +578,7 @@ function formatTest(result: ParseTestResult, options?: FormatTestOptions): strin } else { content += code("See logs for details"); } - return content; + return `${header(3, link(name, url))}\n${content}`; }), ]; })