histoire
Version:
A fast story book powered by Vite
31 lines (30 loc) • 1.48 kB
JavaScript
import { normalize } from 'pathe';
import pc from 'picocolors';
import { reportStuckVitestRun } from '../util/vitest-stuck-run.js';
/**
* Vitest resolves `include` entries as glob patterns, so glob-special
* characters in project paths (SvelteKit `(group)`, Nuxt `[id]`…) can make
* the generated spec paths match nothing — combined with `passWithNoTests`
* the run would "pass" while executing zero specs. Surface the gap loudly.
* @param testModules The test modules Vitest executed.
* @param include The spec paths the run was told to execute.
*/
export function warnAboutMissingTestModules(testModules, include) {
const executed = new Set(testModules.map(module => normalize(module.moduleId)));
const missing = include.filter(path => !executed.has(normalize(path)));
if (!missing.length) {
return;
}
console.warn(pc.yellow(`Histoire generated ${include.length} test spec file(s) but Vitest only executed ${testModules.length}. Missing:`));
for (const file of missing) {
console.warn(pc.yellow(` - ${file}`));
}
console.warn(pc.yellow('If your project path contains glob-special characters ("()", "[]", "{}"), Vitest\'s include globs may not match the generated spec files.'));
}
/**
* Prints what Vitest knows about a test run that never finished.
* @param vitest The Vitest instance of the stuck run.
*/
export function reportStuckTestRun(vitest) {
reportStuckVitestRun(vitest, 'Histoire test run timed out');
}