Created
April 24, 2024 20:44
-
-
Save jgcmarins/816e9e6619a9950cab3eda2dd0f55dd7 to your computer and use it in GitHub Desktop.
vitest config with setup and process.env mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vi.mock('package-to-mock') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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