Skip to content

Commit c52fe99

Browse files
committed
Further improve test output
1 parent 4c629a8 commit c52fe99

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

tests/test.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { cleanupLogger, initializeLogger } from "../src/core/log.ts";
1313
import { quarto } from "../src/quarto.ts";
1414
import { join } from "path/mod.ts";
1515
import * as colors from "fmt/colors.ts";
16-
import { isInteractiveTerminal } from "../src/core/platform.ts";
1716
import { runningInCI } from "../src/core/ci-info.ts";
17+
import { relative } from "path/mod.ts";
1818

1919
export interface TestDescriptor {
2020
// The name of the test
@@ -151,6 +151,7 @@ export function test(test: TestDescriptor) {
151151
return undefined;
152152
}
153153
};
154+
let lastVerify;
154155
try {
155156
await test.execute();
156157

@@ -161,27 +162,50 @@ export function test(test: TestDescriptor) {
161162
const testOutput = logOutput(log);
162163
if (testOutput) {
163164
for (const ver of test.verify) {
165+
lastVerify = ver;
164166
await ver.verify(testOutput);
165167
}
166168
}
167169
} catch (ex) {
168-
const isInteractive = isInteractiveTerminal() && !runningInCI();
170+
const colorize = !runningInCI();
169171
const border = "-".repeat(80);
170-
const coloredName = isInteractive
172+
const coloredName = colorize
171173
? colors.brightGreen(colors.italic(testName))
172174
: testName;
173-
const origin = context.origin.replace("file://", "");
174-
const coloredOrigin = isInteractive
175-
? colors.brightGreen(origin)
176-
: origin;
175+
176+
// Compute an inset based upon the testName
177+
const offset = testName.indexOf(">");
178+
179+
// Form the test runner command
180+
const originUrl = new URL(context.origin);
181+
const absPath = originUrl.pathname;
182+
const relPath = relative(Deno.cwd(), absPath);
183+
const command = Deno.build.os === "windows"
184+
? "run-tests.psl"
185+
: "./run-test.sh";
186+
const testCommand = `${
187+
offset > 0 ? " ".repeat(offset + 2) : ""
188+
}${command} ${relPath}`;
189+
const coloredTestCommand = colorize
190+
? colors.brightGreen(testCommand)
191+
: testCommand;
192+
193+
const verifyFailed = `[verify] > ${
194+
lastVerify ? lastVerify.name : "unknown"
195+
}`;
196+
const coloredVerify = colorize
197+
? colors.brightGreen(verifyFailed)
198+
: verifyFailed;
177199

178200
const logMessages = logOutput(log);
179201
const output: string[] = [
180202
"",
181203
"",
182204
border,
183205
coloredName,
184-
coloredOrigin,
206+
coloredTestCommand,
207+
"",
208+
coloredVerify,
185209
"",
186210
ex.message,
187211
ex.stack,

0 commit comments

Comments
 (0)