Skip to content

Commit

Permalink
fix: resolve reporters passed down to the CLI relative to the running…
Browse files Browse the repository at this point in the history
… directory (#3097)
  • Loading branch information
sheremet-va authored Mar 29, 2023
1 parent 42435d6 commit 93c7e39
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
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

0 comments on commit 93c7e39

Please sign in to comment.