Skip to content

Commit d9be6a5

Browse files
fix: add @vitest/coverage-v8 dep and restructure test helper to assert outside try/catch
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
1 parent 33fac0f commit d9be6a5

File tree

3 files changed

+218
-8
lines changed

3 files changed

+218
-8
lines changed

package-lock.json

Lines changed: 208 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@types/node": "^24.12.0",
4646
"@types/object-hash": "^3.0.6",
4747
"@types/semver": "^7.7.1",
48+
"@vitest/coverage-v8": "^4.1.2",
4849
"eslint": "^10.1.0",
4950
"husky": "^9.1.7",
5051
"lint-staged": "^16.2.7",

packages/js-ofrep-worker/test/invalid-config-test-utils.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ type ErrorWithCause = Error & {
55
export function expectInvalidConfigError(action: () => void, causePattern?: RegExp): void {
66
const consoleDebugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {});
77

8+
let thrownError: ErrorWithCause | undefined;
89
try {
910
action();
10-
throw new Error('Expected invalid flag configuration to throw');
1111
} catch (error) {
12-
const invalidConfigError = error as ErrorWithCause;
13-
14-
expect(invalidConfigError.message).toBe('invalid flagd flag configuration');
15-
16-
if (causePattern) {
17-
expect(invalidConfigError.cause?.message ?? '').toMatch(causePattern);
18-
}
12+
thrownError = error as ErrorWithCause;
1913
} finally {
2014
consoleDebugSpy.mockRestore();
2115
}
16+
17+
expect(thrownError).toBeDefined();
18+
expect(thrownError!.message).toBe('invalid flagd flag configuration');
19+
20+
if (causePattern) {
21+
expect(thrownError!.cause?.message ?? '').toMatch(causePattern);
22+
}
2223
}

0 commit comments

Comments
 (0)