Skip to content

Commit c77893d

Browse files
committed
Improve test output
1 parent 3b563d9 commit c77893d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,38 @@ export function test(test: TestDescriptor) {
123123
quiet: true,
124124
});
125125

126-
let testOutput: ExecuteOutput[] = [];
126+
const logOutput = (path: string) => {
127+
if (existsSync(path)) {
128+
return readExecuteOutput(path);
129+
} else {
130+
return undefined;
131+
}
132+
};
127133
try {
128134
await test.execute();
129135

130136
// Cleanup the output logging
131137
await cleanupLogOnce();
132138

133139
// Read the output
134-
if (existsSync(log)) {
135-
testOutput = readExecuteOutput(log);
136-
Deno.removeSync(log);
140+
const testOutput = logOutput(log);
141+
if (testOutput) {
137142
for (const ver of test.verify) {
138143
await ver.verify(testOutput);
139144
}
140145
}
141146
} catch (ex) {
142-
if (testOutput && testOutput.length > 0) {
143-
const errorTxts = testOutput.map((msg) => msg.msg);
147+
const logMessages = logOutput(log);
148+
if (logMessages && logMessages.length > 0) {
149+
const errorTxts = logMessages.map((msg) => msg.msg);
144150
fail(
145151
`\n---------------------------------------------\n${ex.message}\n${ex.stack}\n\nTEST OUTPUT:\n${errorTxts}----------------------------------------------`,
146152
);
147153
} else {
148154
fail(`${ex.message}\n${ex.stack}`);
149155
}
150156
} finally {
157+
Deno.removeSync(log);
151158
await cleanupLogOnce();
152159
if (test.context.teardown) {
153160
await test.context.teardown();

0 commit comments

Comments
 (0)