forked from Opentrons/opentrons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.mts
More file actions
151 lines (148 loc) · 5.53 KB
/
vitest.config.mts
File metadata and controls
151 lines (148 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* eslint-disable @typescript-eslint/triple-slash-reference */
/// <reference types="vitest" />
/// <reference types="vite/client" />
// todo(mm, 2025-09-15): This file is used under confusing circumstances.
//
// For normal production bundling and dev-serving, each project has its own
// vite.config.mts.
//
// For vitest invocations, vitest would normally default to those same project-specific
// vite.config.mts files. However, because we have this single global
// vitest.config.mts, it uses this instead, completely ignoring the project-specific
// files.
//
// So, that leaves us with:
// - An arbitrary split between this global vite.config.mts the global vitest.config.mts
// - Global vite.config.mts and global vitest.config.mts comprising, together, an
// amalgamation of all projects' needs -- all projects' aliases, all projects' defines, etc.
// - Which is probably largely duplicating the existing project-local configs,
// which we'd get for free if we didn't override them with our vitest.config.mts
import path from 'path'
import react from '@vitejs/plugin-react'
import lostCss from 'lost'
import postCssApply from 'postcss-apply'
import postColorModFunction from 'postcss-color-mod-function'
import postCssImport from 'postcss-import'
import postCssPresetEnv from 'postcss-preset-env'
import { configDefaults, defineConfig } from 'vitest/config'
// eslint-disable-next-line import/no-default-export
export default defineConfig({
build: {
// Relative to the root
outDir: 'dist',
},
plugins: [
react({
include: '**/*.tsx',
babel: {
// Use babel.config.js files
configFile: true,
},
}),
],
optimizeDeps: {
esbuildOptions: {
target: 'es2020',
},
exclude: ['node_modules'],
},
css: {
postcss: {
plugins: [
postCssImport({ root: 'src/' }),
postCssApply(),
postColorModFunction(),
postCssPresetEnv({ stage: 0 }),
lostCss(),
],
},
},
test: {
environment: 'jsdom',
allowOnly: true,
exclude: [
...configDefaults.exclude,
'**/node_modules/**',
'**/dist/**',
'**/lib/**',
],
setupFiles: ['./setup-vitest.mts'],
coverage: {
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/__tests__/**',
'**/lib/**',
'labware-library/cypress/**/*',
...configDefaults.exclude,
],
provider: 'v8',
reporter: ['text', 'json', 'html', 'lcov'],
},
},
define: {
// These defines mimic the ones set in various project-local vite.config.mts files.
// NOTE: For security, only include environment variables here if they're explicitly allowlisted.
_FF_ENV_VARS_: {},
_NODE_ENV_: JSON.stringify(process.env.NODE_ENV),
_OT_AI_CLIENT_MIXPANEL_ID_: JSON.stringify(
process.env.OT_AI_CLIENT_MIXPANEL_ID
),
_OT_APP_MIXPANEL_ID_: JSON.stringify(process.env.OT_APP_MIXPANEL_ID),
_OT_LL_MIXPANEL_DEV_ID_: JSON.stringify(process.env.OT_LL_MIXPANEL_DEV_ID),
_OT_LL_MIXPANEL_ID_: JSON.stringify(process.env.OT_LL_MIXPANEL_ID),
_OT_PD_BUILD_DATE_: JSON.stringify(process.env.OT_PD_BUILD_DATE),
_OT_PD_MIXPANEL_DEV_ID_: JSON.stringify(process.env.OT_PD_MIXPANEL_DEV_ID),
_OT_PD_MIXPANEL_ID_: JSON.stringify(process.env.OT_PD_MIXPANEL_ID),
_OT_PD_SENTRY_DEV_DSN_: JSON.stringify(process.env.OT_PD_SENTRY_DEV_DSN),
_OT_PD_SENTRY_DSN_: JSON.stringify(process.env.OT_PD_SENTRY_DSN),
_OT_PD_VERSION_: JSON.stringify(process.env.OT_PD_VERSION),
global: 'globalThis',
},
resolve: {
alias: {
// todo(mm, 2025-10-27): These cross-project aliases cause trouble like
// files being processed with the wrong config (the config from the
// consuming project vs. the config from the source project).
// Can these be replaced with regular package.json dependencies?
'@opentrons/components/styles': path.resolve(
'./components/src/index.module.css'
),
'@opentrons/components': path.resolve('./components/src/index.ts'),
'@opentrons/shared-data/pipette/fixtures/name': path.resolve(
'./shared-data/pipette/fixtures/name/index.ts'
),
'@opentrons/shared-data/labware/fixtures/1': path.resolve(
'./shared-data/labware/fixtures/1/index.ts'
),
'@opentrons/shared-data/labware/fixtures/2': path.resolve(
'./shared-data/labware/fixtures/2/index.ts'
),
'@opentrons/shared-data/labware/fixtures/3': path.resolve(
'./shared-data/labware/fixtures/3/index.ts'
),
'@opentrons/shared-data': path.resolve('./shared-data/js/index.ts'),
'@opentrons/step-generation': path.resolve(
'./step-generation/src/index.ts'
),
'@opentrons/api-client': path.resolve('./api-client/src/index.ts'),
'@opentrons/react-api-client': path.resolve(
'./react-api-client/src/index.ts'
),
'@opentrons/discovery-client': path.resolve(
'./discovery-client/src/index.ts'
),
'@opentrons/usb-bridge/node-client': path.resolve(
'./usb-bridge/node-client/src/index.ts'
),
'@opentrons/labware-library': path.resolve(
'./labware-library/src/labware-creator/index.tsx'
),
// "The resulting path (...) trailing slashes are removed unless the path is resolved to the root directory."
// https://nodejs.org/api/path.html#pathresolvepaths
'/app/': path.resolve('./app/src/') + '/',
'/protocol-designer/': path.resolve('./protocol-designer/src/') + '/',
'/ai-client/': path.resolve('./opentrons-ai-client/src/') + '/',
},
},
})