Take vitest to 4.1.11, and stop two suites leaking their spies
GHSA-82fw-gwwq-j7x9 -- arbitrary file read through @vitest/mocker's redirect mock -- has no fix in the 3.x line. The patched versions are 4.1.11 and 5.0.0-rc.2, so clearing it means the major. vite stays at 6.4.3: vitest 4 accepts ^6, and nothing outside devDependencies moves. The bump surfaced a bug of ours rather than one of vitest's. vi.spyOn now hands back the spy already installed on a method instead of wrapping it in a fresh one, so a spy installed in beforeEach keeps its call count across tests. compose-from-share expected two uploads and saw three: its own two, plus the one from the test before it. The assertion was only ever passing because each test happened to get a new spy. Both suites now restore between tests, which is what the other five spying suites already do. webpush had the same leak with no assertion close enough to catch it.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { useCompose } from "@/store/compose";
|
||||
import { useMail } from "@/store/mail";
|
||||
import { client } from "@/jmap/client";
|
||||
@@ -34,6 +34,13 @@ beforeEach(() => {
|
||||
vi.spyOn(client, "upload").mockResolvedValue({ blobId: "b1", type: "image/png", size: 6 } as never);
|
||||
});
|
||||
|
||||
// Without this the spy installed above is the same one every test, so its call
|
||||
// count is cumulative and "uploaded twice" quietly means "twice, plus whatever
|
||||
// the test before it uploaded".
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
const draftFor = (key: string) => useCompose.getState().drafts.find((d) => d.key === key)!;
|
||||
|
||||
describe("opening a share as a draft", () => {
|
||||
|
||||
Reference in New Issue
Block a user