Skip to content

Commit 913cd47

Browse files
committed
Add checkExpectedLogMessages function to testing-utils
1 parent 4f14649 commit 913cd47

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/testing-utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TextDecoder } from "node:util";
22
import path from "path";
33

44
import * as github from "@actions/github";
5-
import { TestFn } from "ava";
5+
import { ExecutionContext, TestFn } from "ava";
66
import nock from "nock";
77
import * as sinon from "sinon";
88

@@ -180,6 +180,23 @@ export function getRecordingLogger(messages: LoggedMessage[]): Logger {
180180
};
181181
}
182182

183+
export function checkExpectedLogMessages(
184+
t: ExecutionContext<any>,
185+
messages: LoggedMessage[],
186+
expectedMessages: string[],
187+
) {
188+
for (const expectedMessage of expectedMessages) {
189+
t.assert(
190+
messages.some(
191+
(msg) =>
192+
typeof msg.message === "string" &&
193+
msg.message.includes(expectedMessage),
194+
),
195+
`Expected '${expectedMessage}' in the logger output, but didn't find it in:\n ${messages.map((m) => ` - '${m.message}'`).join("\n")}`,
196+
);
197+
}
198+
}
199+
183200
/** Mock the HTTP request to the feature flags enablement API endpoint. */
184201
export function mockFeatureFlagApiEndpoint(
185202
responseStatusCode: number,

0 commit comments

Comments
 (0)