Skip to content

Instantly share code, notes, and snippets.

@jgcmarins
Created April 24, 2024 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgcmarins/816e9e6619a9950cab3eda2dd0f55dd7 to your computer and use it in GitHub Desktop.
Save jgcmarins/816e9e6619a9950cab3eda2dd0f55dd7 to your computer and use it in GitHub Desktop.
vitest config with setup and process.env mock
// https://github.com/vitest-dev/vitest/issues/1575#issuecomment-1439286286
export const setup = () => {
process.env.TZ = 'UTC';
process.env.NODE_ENV = 'test';
// add process.env mocks
};
vi.mock('package-to-mock')
import { resolve } from 'path';
import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vitest/config';
/**
* @see {@link https://vitejs.dev/config/}
* @see {@link https://vitest.dev/config/}
*/
export default defineConfig({
plugins: [react()],
test: {
globals: true,
setupFiles: resolve(__dirname, 'test/setup.ts'),
globalSetup: resolve(__dirname, 'test/setup-env.ts'),
coverage: {
all: true,
},
// ref: https://vitest.dev/config/#testtimeout
testTimeout: 10000,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment