const test = baseTest.extend({ db: [ async ({}, use) => { // ...setup await use(db) await db.close() }, { scope: 'worker' }, ], })自定义项目名称颜色功能让多项目测试更直观,浏览器定位器 API 扩展支持 Playwright 定位器字符串,增强了浏览器测试能力。新增 signalAPI 可在测试超时或手动中止时终止运行,结合 V8 AST 感知重映射(需启用 coverage.experimentalAstAwareRemapping),显著提升代码覆盖率性能。
it('stop request when test times out', async ({ signal }) => { await fetch('/heavy-resource', { signal }) }, 2000)此外,watchTriggerPatterns 允许配置特定文件更改触发相关测试,如模板文件更改触发 mailers 测试,提升开发效率。
export default defineConfig({ test: { watchTriggerPatterns: [ { pattern: /^src\/templates\/(.*)\.(ts|html|txt)$/, testsToRun: (file, match) => { return `api/tests/mailers/${match[2]}.test.ts` }, }, ], }, })另外本次更新将弃用 workspace ,改用 projects
import { defineConfig } from "vitest/config"; export default defineConfig({ test: { // "test.workspace" is now "test.projects" // 堆代码 duidaima.com projects: [ { test: { name: "Unit" } }, { test: { name: "Integration" } }, ], }, });
2.已停止对 Node 18 的支持。Vite 现已仅以 ESM 形式发行