@bitcurve/reactor-configs-vitest
v0.0.0
Published
Vitest app + library project configurations intended for pnpm workspaces (monorepos): `vitest.config.ts`.
Downloads
4
Readme
@bitcurve/reactor-configs-vitest
Vitest app + library project configurations intended for pnpm workspaces (monorepos): vitest.config.ts
.
Configuration
Workspace
Ensure the workspace root has a vitest.workspace.ts
similar to the following that lists the directories subject to testing:
import { defineWorkspace } from 'vitest/config'
/**
* Vitest workspace configuration.
*
* @see https://vitest.dev/guide/workspace
*/
export default defineWorkspace([
'apps/*',
'packages/*',
// glob patterns are supported to match file extensions --
// 'packages/*/vitest.config.{e2e,unit}.ts',
{
// if a global vite config file is present you may wish to extend it...
// extends: './vite.config.js',
test: {
// environment: 'jsdom',
// ... other global test settings
},
},
])
When defining a vitest.config.ts
for individual apps or packages (projects) within the workspace use defineProject()
instead of defineConfig()
because workspace projects do not support all vitest configuration options.
React + Vite Projects
React
The vitest-react.project.config.ts
config references vite.config.ts
and requires a setup file at './test/setup.ts'
.
Example ./test/setup.ts
:
import { expect, afterEach } from 'vitest'
import { cleanup } from '@testing-library/react'
import * as matchers from '@testing-library/jest-dom/matchers'
import '@testing-library/jest-dom/vitest'
expect.extend(matchers)
afterEach(() => {
cleanup()
})
Example stub test:
import { describe, it, expect } from 'vitest'
// pnpm --filter @bitcurve/reactor-<project-name> test test/stub.test.ts
describe('@bitcurve/reactor-<project-name> test stub', () => {
it('stub test always passes', () => {
expect(true).toBe(true)
})
})