(configEnv: ConfigEnv)
| 225 | }) |
| 226 | |
| 227 | async function loadConfig(configEnv: ConfigEnv) { |
| 228 | let config: UserConfig | null = null |
| 229 | |
| 230 | // config file named by convention as the *.spec.ts folder |
| 231 | const variantName = path.basename(path.dirname(testPath)) |
| 232 | if (variantName !== '__tests__') { |
| 233 | const configVariantPath = path.resolve( |
| 234 | rootDir, |
| 235 | `vite.config-${variantName}.js`, |
| 236 | ) |
| 237 | if (fs.existsSync(configVariantPath)) { |
| 238 | const res = await loadConfigFromFile(configEnv, configVariantPath) |
| 239 | if (res) { |
| 240 | config = res.config |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | // config file from test root dir |
| 245 | if (!config) { |
| 246 | const res = await loadConfigFromFile(configEnv, undefined, rootDir) |
| 247 | if (res) { |
| 248 | config = res.config |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | const options: InlineConfig = { |
| 253 | root: rootDir, |
| 254 | logLevel: 'silent', |
| 255 | configFile: false, |
| 256 | server: { |
| 257 | watch: { |
| 258 | // During tests we edit the files too fast and sometimes chokidar |
| 259 | // misses change events, so enforce polling for consistency |
| 260 | usePolling: true, |
| 261 | interval: 100, |
| 262 | }, |
| 263 | }, |
| 264 | build: { |
| 265 | // esbuild do not minify ES lib output since that would remove pure annotations and break tree-shaking |
| 266 | // skip transpilation during tests to make it faster |
| 267 | target: 'esnext', |
| 268 | }, |
| 269 | customLogger: createInMemoryLogger(serverLogs), |
| 270 | plugins: [throwHtmlParseError()], |
| 271 | } |
| 272 | return mergeConfig(options, config || {}) |
| 273 | } |
| 274 | |
| 275 | export async function startDefaultServe(): Promise<void> { |
| 276 | setupConsoleWarnCollector(serverLogs) |
no test coverage detected