Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve reporters passed down to the CLI relative to the running directory #3097

Merged
merged 4 commits into from Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/vitest/src/node/config.ts
Expand Up @@ -212,9 +212,16 @@ export function resolveConfig(
resolved.related = toArray(options.related).map(file => resolve(resolved.root, file))

if (mode !== 'benchmark') {
// @ts-expect-error from CLI
const reporters = resolved.reporter ?? resolved.reporters
resolved.reporters = Array.from(new Set(toArray(reporters))).filter(Boolean)
// @ts-expect-error "reporter" is from CLI, should be absolute to the running directory
// it is passed down as "vitest --reporter ../reporter.js"
const cliReporters = toArray(resolved.reporter || []).map((reporter: string) => {
// ./reporter.js || ../reporter.js, but not .reporters/reporter.js
if (/^\.\.?\//.test(reporter))
return resolve(process.cwd(), reporter)
return reporter
})
const reporters = cliReporters.length ? cliReporters : resolved.reporters
resolved.reporters = Array.from(new Set(toArray(reporters as 'json'[]))).filter(Boolean)
}

if (!resolved.reporters.length)
Expand Down