import path from "node:path"; /** * Vitest matches `coverage.include` and `coverage.exclude` against each * module's absolute path with picomatch `contains: true`, so a relative * pattern may match anywhere in that path. `src/**` also matched * `/vite.config.ts` when the checkout sat in a folder whose name * ends in `src` (`~/work/app-src/`), and risk coverage then failed on rows * outside the repository inventory. A pattern that starts with the root * matches only inside it. * * The root is escaped with the expression Vitest's glob library (tinyglobby * 0.2) uses for a cwd, so a root with glob characters still matches itself * literally and the untested-file glob resolves the pattern back to * `src/...` under that cwd. A Windows root is turned into forward slashes * first; for a valid Windows path that escape equals tinyglobby's Windows one. */ const UNESCAPED_GLOB_SYMBOLS = /(? { if ( pattern.length === 0 || pattern.startsWith("/") || pattern.startsWith("!") || pattern.includes("\\") || pattern.split("/").includes("..") ) { throw new TypeError( `coverage pattern must be a forward-slash path inside the root: ${pattern}`, ); } return `${escapedRoot.replace(/\/$/u, "")}/${pattern}`; }); }