Skip to content

Commit 325a3a2

Browse files
committed
Add wrapFailureTest test macro
1 parent 6394750 commit 325a3a2

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/start-proxy.test.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as core from "@actions/core";
22
import * as toolcache from "@actions/tool-cache";
3-
import test from "ava";
3+
import test, { ExecutionContext } from "ava";
44
import sinon from "sinon";
55

66
import * as apiClient from "./api-client";
77
import * as defaults from "./defaults.json";
88
import { KnownLanguage } from "./languages";
9-
import { getRunnerLogger } from "./logging";
9+
import { getRunnerLogger, Logger } from "./logging";
1010
import * as startProxyExports from "./start-proxy";
1111
import { parseLanguage } from "./start-proxy";
1212
import * as statusReport from "./status-report";
@@ -384,6 +384,23 @@ test("getSafeErrorMessage - does not return message for arbitrary errors", (t) =
384384
t.assert(message.includes(typeof error));
385385
});
386386

387+
const wrapFailureTest = test.macro({
388+
exec: async (
389+
t: ExecutionContext<unknown>,
390+
setup: () => void,
391+
fn: (logger: Logger) => Promise<void>,
392+
) => {
393+
const loggedMessages = [];
394+
const logger = getRecordingLogger(loggedMessages);
395+
setup();
396+
397+
await t.throwsAsync(fn(logger), {
398+
instanceOf: startProxyExports.StartProxyError,
399+
});
400+
},
401+
title: (providedTitle) => `${providedTitle} - wraps errors on failure`,
402+
});
403+
387404
test("downloadProxy - returns file path on success", async (t) => {
388405
const loggedMessages = [];
389406
const logger = getRecordingLogger(loggedMessages);
@@ -398,15 +415,13 @@ test("downloadProxy - returns file path on success", async (t) => {
398415
t.is(result, testPath);
399416
});
400417

401-
test("downloadProxy - wraps errors on failure", async (t) => {
402-
const loggedMessages = [];
403-
const logger = getRecordingLogger(loggedMessages);
404-
sinon.stub(toolcache, "downloadTool").throws();
405-
406-
await t.throwsAsync(
407-
startProxyExports.downloadProxy(logger, "url", undefined),
408-
{
409-
instanceOf: startProxyExports.StartProxyError,
410-
},
411-
);
412-
});
418+
test(
419+
"downloadProxy",
420+
wrapFailureTest,
421+
() => {
422+
sinon.stub(toolcache, "downloadTool").throws();
423+
},
424+
async (logger) => {
425+
await startProxyExports.downloadProxy(logger, "url", undefined);
426+
},
427+
);

0 commit comments

Comments
 (0)