test: require a matcher for every toThrow assertion (#15577)

A bare toThrow() or rejects.toThrow() passes on any error, including one
from a broken fixture or a refusal for the wrong reason. The suite's 429
bare sites now assert the specific refusal, so turn on
vitest/require-to-throw-message as an error to keep it that way.

Tighten the one site added since (malformed TOML now asserts smol-toml's
line and column). The two sites whose refusal cannot be observed outside
Linux or without a native capture bound keep a bare matcher with a
disable comment saying why.
This commit is contained in:
morluto
2026-12-01 14:03:47 -05:00
committed by GitHub
parent 65499cd329
commit 6991e735a2
4 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -35,7 +35,7 @@
"vitest/expect-expect": "off",
"vitest/no-disabled-tests": "off",
"vitest/require-mock-type-parameters": "off",
"vitest/require-to-throw-message": "off",
"vitest/require-to-throw-message": "error",
"import/no-duplicates": [
"warn",
{
@@ -33,7 +33,10 @@ describe("parseClientToml", () => {
});
it("rejects malformed TOML syntax", () => {
expect(() => parseClientToml("[unterminated\nkey = 1\n")).toThrow();
// smol-toml reports where the unterminated table header stops parsing.
expect(() => parseClientToml("[unterminated\nkey = 1\n")).toThrow(
expect.objectContaining({ line: 1, column: 14 }),
);
});
});
+1
View File
@@ -122,6 +122,7 @@ it.skipIf(process.platform !== "linux").each([false, true])(
const selected = closeFault.handles.at(-1);
if (selected === undefined) throw new Error("Missing database descriptor");
first.allow();
// oxlint-disable-next-line vitest/require-to-throw-message -- Linux-only fixture; its retry refusal has not been observed, and the lease state below is the asserted fact.
await expect(failure.cleanupLease.release()).rejects.toThrow();
expect(failure.cleanupLease.released).toBe(false);
await expect(first.handle.stat()).rejects.toMatchObject({ code: "EBADF" });
@@ -781,6 +781,7 @@ it.skipIf(!hasNativeBound)(
expect(result.error.cleanupIncomplete).toBe(true);
// Releasing only the snapshot leaves the primary cleanup failure open.
// oxlint-disable-next-line vitest/require-to-throw-message -- needs a native capture bound to observe the refusal; the cleanup facts below are the asserted ones.
await expect(provider.close()).rejects.toThrow();
expect(result.error.cleanupResources).toEqual([resolvedCapinfos]);
expect(result.error.cleanupIncomplete).toBe(true);