Skip to content

Commit

Permalink
sort out vitest with setup stuff as well as loading correct envs
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Sep 19, 2024
1 parent d8c6af2 commit 79f70a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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()
})
4 changes: 4 additions & 0 deletions vitest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loadEnv } from 'vite'
import { defineConfig, mergeConfig } from 'vitest/config'

import ViteConfig from './vite.config.mjs'
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 79f70a0

Please sign in to comment.