Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add and use withRecordingLoggerAsync
  • Loading branch information
mbg committed Jan 29, 2026
commit 05bd050f34dab49564f92e80d2efe16c7058a843
33 changes: 17 additions & 16 deletions src/start-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getRecordingLogger,
makeTestToken,
setupTests,
withRecordingLoggerAsync,
} from "./testing-utils";

setupTests(test);
Expand Down Expand Up @@ -390,29 +391,29 @@ const wrapFailureTest = test.macro({
setup: () => void,
fn: (logger: Logger) => Promise<void>,
) => {
const loggedMessages = [];
const logger = getRecordingLogger(loggedMessages);
setup();
await withRecordingLoggerAsync(async (logger) => {
setup();

await t.throwsAsync(fn(logger), {
instanceOf: startProxyExports.StartProxyError,
await t.throwsAsync(fn(logger), {
instanceOf: startProxyExports.StartProxyError,
});
});
},
title: (providedTitle) => `${providedTitle} - wraps errors on failure`,
});

test("downloadProxy - returns file path on success", async (t) => {
const loggedMessages = [];
const logger = getRecordingLogger(loggedMessages);
const testPath = "/some/path";
sinon.stub(toolcache, "downloadTool").resolves(testPath);

const result = await startProxyExports.downloadProxy(
logger,
"url",
undefined,
);
t.is(result, testPath);
await withRecordingLoggerAsync(async (logger) => {
const testPath = "/some/path";
sinon.stub(toolcache, "downloadTool").resolves(testPath);

const result = await startProxyExports.downloadProxy(
logger,
"url",
undefined,
);
t.is(result, testPath);
});
});

test(
Expand Down
17 changes: 17 additions & 0 deletions src/testing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,23 @@ export function checkExpectedLogMessages(
}
}

/**
* Initialises a recording logger and calls `body` with it.
*
* @param body The test that requires a recording logger.
* @returns The logged messages.
*/
export async function withRecordingLoggerAsync(
body: (logger: Logger) => Promise<void>,
): Promise<LoggedMessage[]> {
const messages = [];
const logger = getRecordingLogger(messages);

await body(logger);

return messages;
}

/** Mock the HTTP request to the feature flags enablement API endpoint. */
export function mockFeatureFlagApiEndpoint(
responseStatusCode: number,
Expand Down