test: fix leaking global module mock
This commit is contained in:
parent
26bec15b71
commit
416ce732fc
2 changed files with 17 additions and 16 deletions
|
|
@ -1,23 +1,23 @@
|
||||||
import { test, describe, mock, expect, beforeEach } from "bun:test";
|
import { test, describe, mock, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
||||||
import { backupsService } from "../backups.service";
|
import { backupsService } from "../backups.service";
|
||||||
import { createTestVolume } from "~/test/helpers/volume";
|
import { createTestVolume } from "~/test/helpers/volume";
|
||||||
import { createTestBackupSchedule } from "~/test/helpers/backup";
|
import { createTestBackupSchedule } from "~/test/helpers/backup";
|
||||||
import { createTestRepository } from "~/test/helpers/repository";
|
import { createTestRepository } from "~/test/helpers/repository";
|
||||||
import { generateBackupOutput } from "~/test/helpers/restic";
|
import { generateBackupOutput } from "~/test/helpers/restic";
|
||||||
import { getVolumePath } from "../../volumes/helpers";
|
import { getVolumePath } from "../../volumes/helpers";
|
||||||
|
import { restic } from "~/server/utils/restic";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
const backupMock = mock(() => Promise.resolve({ exitCode: 0, result: generateBackupOutput() }));
|
const backupMock = mock(() => Promise.resolve({ exitCode: 0, result: JSON.parse(generateBackupOutput()) }));
|
||||||
|
|
||||||
mock.module("~/server/utils/restic", () => ({
|
|
||||||
restic: {
|
|
||||||
backup: backupMock,
|
|
||||||
forget: mock(() => Promise.resolve()),
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
backupMock.mockClear();
|
backupMock.mockClear();
|
||||||
|
spyOn(restic, "backup").mockImplementation(backupMock);
|
||||||
|
spyOn(restic, "forget").mockImplementation(mock(() => Promise.resolve({ success: true })));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
mock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("executeBackup - include / exclude patterns", () => {
|
describe("executeBackup - include / exclude patterns", () => {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
import { test, describe, mock, expect } from "bun:test";
|
import { test, describe, mock, expect, beforeEach, afterEach, spyOn } from "bun:test";
|
||||||
import { backupsService } from "../backups.service";
|
import { backupsService } from "../backups.service";
|
||||||
import { createTestVolume } from "~/test/helpers/volume";
|
import { createTestVolume } from "~/test/helpers/volume";
|
||||||
import { createTestBackupSchedule } from "~/test/helpers/backup";
|
import { createTestBackupSchedule } from "~/test/helpers/backup";
|
||||||
import { createTestRepository } from "~/test/helpers/repository";
|
import { createTestRepository } from "~/test/helpers/repository";
|
||||||
import { generateBackupOutput } from "~/test/helpers/restic";
|
import { generateBackupOutput } from "~/test/helpers/restic";
|
||||||
import { beforeEach } from "bun:test";
|
import * as spawnModule from "~/server/utils/spawn";
|
||||||
|
|
||||||
const resticBackupMock = mock(() => Promise.resolve({ exitCode: 0 }));
|
const resticBackupMock = mock(() => Promise.resolve({ exitCode: 0, stdout: "", stderr: "" }));
|
||||||
|
|
||||||
mock.module("~/server/utils/spawn", () => ({
|
|
||||||
safeSpawn: resticBackupMock,
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
resticBackupMock.mockClear();
|
resticBackupMock.mockClear();
|
||||||
|
spyOn(spawnModule, "safeSpawn").mockImplementation(resticBackupMock);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
mock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("execute backup", () => {
|
describe("execute backup", () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue