Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/api/src/api/middlewares/vortexAdminAuth.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, spyOn } from "bun:test";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
import express, { Request, Response } from "express";
import { config } from "../../config/vars";
import ProfileRole from "../../models/profileRole.model";
Expand Down Expand Up @@ -39,6 +39,7 @@ describe("requireVortexAdmin", () => {
});

afterEach(() => {
mock.restore();
config.impersonationEnabled = originalImpersonationEnabled;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, spyOn } from "bun:test";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
import express from "express";
import { config } from "../../../../config/vars";
import AdminImpersonationSession from "../../../../models/adminImpersonationSession.model";
Expand Down Expand Up @@ -42,6 +42,7 @@ describe("admin-console routes", () => {
});

afterEach(() => {
mock.restore();
config.impersonationEnabled = originalImpersonationEnabled;
});

Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/api/services/impersonation.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, spyOn } from "bun:test";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
import crypto from "crypto";
import { config } from "../../config/vars";
import AdminImpersonationSession from "../../models/adminImpersonationSession.model";
Expand Down Expand Up @@ -28,6 +28,7 @@ describe("impersonation.service", () => {
});

afterEach(() => {
mock.restore();
config.impersonationEnabled = originalImpersonationEnabled;
});

Expand Down
18 changes: 18 additions & 0 deletions apps/api/src/tests/spy-restore.invariants.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect, it } from "bun:test";
import { join } from "path";

// bun restores a spied method when its test file ends but keeps the spy's call history: a
// later file's spyOn() on the same method then starts with calls that file never made.
it("every test file that installs spyOn() spies restores them", async () => {
const root = join(import.meta.dir, "..");
const offenders: string[] = [];
for await (const path of new Bun.Glob("**/*.test.ts").scan(root)) {
const file = join(root, path);
if (file === import.meta.path) continue;
const source = await Bun.file(file).text();
if (source.includes("spyOn(") && !/mock\.restore\(\)|\.mockRestore\(\)/.test(source)) {
offenders.push(path);
}
}
expect(offenders).toEqual([]);
});
Loading