From f9949a04f6a0135b7fb23cfac4a562d922849ae5 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 28 Jan 2026 23:02:37 +0000 Subject: [PATCH] test(linter/plugins): conformance tester catch errors in `describe` callbacks (#18678) Catch errors in `describe(() => { ... })` blocks and turn them into test cases. This results in a failing test rather than the whole test file failing to load. --- apps/oxlint/conformance/src/capture.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/oxlint/conformance/src/capture.ts b/apps/oxlint/conformance/src/capture.ts index 3c1b84692ca93..9915bb2c02f30 100644 --- a/apps/oxlint/conformance/src/capture.ts +++ b/apps/oxlint/conformance/src/capture.ts @@ -82,9 +82,23 @@ export function setCurrentTest(test: TestCase): void { export function describe(name: string, fn: () => void): void { describeStack.push(name); try { - fn(); - } finally { + const res = fn() as any; + + // If returned a promise, ignore the promise's rejection, and create a test case which throws an error, + // so it appears in the snapshot. This can only happen if `describe` is used manually. + if (res instanceof Promise) { + res.catch(() => {}); + throw new Error("Test case returned a promise"); + } + + describeStack.pop(); + } catch (err) { + // Error. Treat it as a test case (`it`), so it ends up in snapshot and doesn't cause the file to fail to load. + // This is useful for test files which use `describe` and `it` manually. describeStack.pop(); + it(name, () => { + throw err; + }); } }