From af31001b574eb36e91bf86cdc22fed808a654215 Mon Sep 17 00:00:00 2001 From: Jacek Kolodziejczyk Date: Thu, 17 Jul 2025 21:36:45 +0200 Subject: [PATCH] Fix vitest config to make it run in node environment --- tests/setup.ts | 5 +++++ vitest.config.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/setup.ts diff --git a/tests/setup.ts b/tests/setup.ts new file mode 100644 index 00000000..abb2ead4 --- /dev/null +++ b/tests/setup.ts @@ -0,0 +1,5 @@ +import { vi } from 'vitest' +import { webcrypto } from 'node:crypto' + +// Mock the global crypto object to use Node.js webcrypto +vi.stubGlobal('crypto', webcrypto) diff --git a/vitest.config.ts b/vitest.config.ts index cb2d2d32..c4ce30d0 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -5,7 +5,8 @@ export default defineConfig({ test: { globals: true, // so can use `describe`/`it` without importing them environment: 'node', - include: ['tests/**/*.test.{js,ts}'], + include: ['tests/**/*.test.{js,ts}'], + setupFiles: ['./tests/setup.ts'], }, define: {