From 79f70a04c3a38d6aa99f153a28ebf7bfd5ead406 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 19 Sep 2024 07:42:03 -0300 Subject: [PATCH] sort out vitest with setup stuff as well as loading correct envs --- src/vitest.setup.ts | 27 ++++++++++++++++++++++----- vitest.config.mjs | 4 ++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/vitest.setup.ts b/src/vitest.setup.ts index fd63776896..04b5458531 100644 --- a/src/vitest.setup.ts +++ b/src/vitest.setup.ts @@ -1,15 +1,12 @@ import * as matchers from '@testing-library/jest-dom/matchers' import { cleanup } from '@testing-library/react' -import { afterEach, expect } from 'vitest' +import { vi } from 'vitest' +import '@testing-library/jest-dom/vitest' // not sure why this lint is being fired here so I'm disabling it // eslint-disable-next-line testing-library/await-fire-event expect.extend(matchers) -afterEach(() => { - cleanup() -}) - // Prevent timezone differences between local and CI/CD const setupTestGlobal = async () => { process.env.TZ = 'UTC' @@ -18,3 +15,23 @@ const setupTestGlobal = async () => { export default setupTestGlobal process.env.REACT_APP_ZOD_IGNORE_TESTS = 'true' + +vi.mock('@sentry/react', async () => { + const originalModule = await vi.importActual('@sentry/react') + + return { + ...originalModule, + setUser: vi.fn(), + metrics: { + ...originalModule.metrics!, + distribution: vi.fn(), + gauge: vi.fn(), + increment: vi.fn(), + set: vi.fn(), + }, + } +}) + +afterEach(() => { + cleanup() +}) diff --git a/vitest.config.mjs b/vitest.config.mjs index e557deb3f0..a84a5dae97 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -1,3 +1,4 @@ +import { loadEnv } from 'vite' import { defineConfig, mergeConfig } from 'vitest/config' import ViteConfig from './vite.config.mjs' @@ -34,8 +35,11 @@ const VitestConfig = defineConfig((config) => { reporters.push(['junit', { outputFile: 'reports/junit/junit.xml' }]) } + const env = loadEnv(config.mode, process.cwd(), 'REACT_APP') + return { test: { + env: env, coverage: { include: ['src/**/*'], exclude: EXCLUDE_FROM_COVERAGE,