Skip to content

Commit

Permalink
use fetch pool forks
Browse files Browse the repository at this point in the history
to prevent leaving processes running in the background, see https://vitest.dev/guide/common-errors.html#failed-to-terminate-worker
  • Loading branch information
DavidSint committed Feb 3, 2024
1 parent 2847f21 commit e878c15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
26 changes: 13 additions & 13 deletions lib/tests/hibp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ describe("Have I Been Pwned", () => {
test("non-node web crypto API hash", async () => {
const cryptoSafeBox = globalThis.crypto;

Object.defineProperty(globalThis, 'crypto', {
value: {
getRandomValues: vi
.fn()
.mockImplementation(async () => new ArrayBuffer(16)),
randomUUID: vi.fn() as MockedFunction<typeof cryptoSafeBox.randomUUID>,
subtle: {
...cryptoSafeBox?.subtle,
digest: vi.fn().mockImplementation(async () => new ArrayBuffer(16)),
},
},
writable: true,
});
Object.defineProperty(globalThis, "crypto", {
value: {
getRandomValues: vi
.fn()
.mockImplementation(async () => new ArrayBuffer(16)),
randomUUID: vi.fn() as MockedFunction<typeof cryptoSafeBox.randomUUID>,
subtle: {
...cryptoSafeBox?.subtle,
digest: vi.fn().mockImplementation(async () => new ArrayBuffer(16)),
},
},
writable: true,
});

await createSha1Hash("123934534f", {} as NodeJS.Process);

Expand Down
5 changes: 4 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ module.exports = defineConfig({
fileName: (format) => `password-tester.${format}.js`
}
},
plugins: [dts()]
plugins: [dts()],
test: {
pool: 'forks',
},
})

0 comments on commit e878c15

Please sign in to comment.