Flaky admin browser test: wxr-import.test.ts fails with "vi.mocked(...).mockReset is not a function"
Description
The admin browser test packages/admin/tests/lib/wxr-import.test.ts, "executeWxrImport › drives every phase and aggregates content, taxonomy, and section results", fails intermittently in the Browser Tests job:
FAIL chromium tests/lib/wxr-import.test.ts > executeWxrImport > drives every phase and aggregates content, taxonomy, and section results
TypeError: vi.mocked(...).mockReset is not a functionSeen in Browser Tests on #3548, which doesn't touch the admin package. A rerun of the same commit passed, and the file passes locally (npx vitest run tests/lib/wxr-import.test.ts in packages/admin).
What the error means
The failure is in beforeEach, before the test body runs:
vi.mock("../../src/lib/api/client.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../../src/lib/api/client.js")>();
return { ...actual, apiFetch: vi.fn() };
});
import { apiFetch } from "../../src/lib/api/client.js";
// ...
beforeEach(() => {
vi.mocked(apiFetch).mockReset();
});mockReset is not a function means apiFetch was the real function, not the vi.fn() from the factory. So in the failing run the module mock wasn't in place when the file imported client.js. I haven't found why it only happens sometimes in browser mode; around ten other admin test files mock the same module and don't show this.
Not a regression from the PR it was observed on
The test was added on Sept 27 in #3439. The PR where it failed changes only packages/registry-loader and apps/plugins-site.
Source: emdash-cms/emdash