Problem
In backend/src/lib/__tests__/encryptionKey.test.ts (PR #107 / fix/98), vi.mock() calls appear inside individual it() callbacks rather than at the top level of the module:
it("throws when no encryption secret is configured", async () => {
vi.mock("../supabase.js", () => ({ ... })); // ← nested inside it()
...
});
Vitest currently hoists all vi.mock() calls to before the test suite runs regardless of where they appear (this is the Babel/vite-plugin-vitest transform behaviour). The existing vitest run emits a warning:
Warning: A vi.mock("../supabase.js") call in "...encryptionKey.test.ts" is not at the top level of the module.
Although it appears nested, it will be hoisted and executed before any tests run.
Move it to the top level to reflect its actual execution order.
This will become an error in a future version.
Because all three vi.mock calls mock the same module identity with the same factory, the tests currently pass. But the warning explicitly states this will become an error in a future vitest release, and the nesting gives a false impression that the mock is scoped to the individual test.
Fix
Move the vi.mock("../supabase.js", ...)) call to the top level of the file (after imports, before the describe block), and use vi.mocked(...).mockImplementation() or mockReturnValue() inside each it() if different behaviour per test is needed.
Problem
In
backend/src/lib/__tests__/encryptionKey.test.ts(PR #107 / fix/98),vi.mock()calls appear inside individualit()callbacks rather than at the top level of the module:Vitest currently hoists all
vi.mock()calls to before the test suite runs regardless of where they appear (this is the Babel/vite-plugin-vitest transform behaviour). The existing vitest run emits a warning:Because all three
vi.mockcalls mock the same module identity with the same factory, the tests currently pass. But the warning explicitly states this will become an error in a future vitest release, and the nesting gives a false impression that the mock is scoped to the individual test.Fix
Move the
vi.mock("../supabase.js", ...))call to the top level of the file (after imports, before thedescribeblock), and usevi.mocked(...).mockImplementation()ormockReturnValue()inside eachit()if different behaviour per test is needed.