Skip to content

Commit

Permalink
fix(coverage): log info only when terminal reporter is used (#4027)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Aug 28, 2023
1 parent e691a9c commit 9f04386
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/coverage-istanbul/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"istanbul-lib-report": "^3.0.1",
"istanbul-lib-source-maps": "^4.0.1",
"istanbul-reports": "^3.1.5",
"picocolors": "^1.0.0",
"test-exclude": "^6.0.0"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from 'pathe'
import type { AfterSuiteRunMeta, CoverageIstanbulOptions, CoverageProvider, ReportContext, ResolvedCoverageOptions, Vitest } from 'vitest'
import { coverageConfigDefaults, defaultExclude, defaultInclude } from 'vitest/config'
import { BaseCoverageProvider } from 'vitest/coverage'
import c from 'picocolors'
import libReport from 'istanbul-lib-report'
import reports from 'istanbul-reports'
import type { CoverageMap } from 'istanbul-lib-coverage'
Expand Down Expand Up @@ -134,6 +135,9 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
watermarks: this.options.watermarks,
})

if (hasTerminalReporter(this.options.reporter))
this.ctx.logger.log(c.blue(' % ') + c.dim('Coverage report from ') + c.yellow(this.name))

for (const reporter of this.options.reporter) {
reports.create(reporter[0], {
skipFull: this.options.skipFull,
Expand Down Expand Up @@ -253,3 +257,11 @@ function isEmptyCoverageRange(range: libCoverage.Range) {
|| range.end.column === undefined
)
}

function hasTerminalReporter(reporters: Options['reporter']) {
return reporters.some(([reporter]) =>
reporter === 'text'
|| reporter === 'text-summary'
|| reporter === 'text-lcov'
|| reporter === 'teamcity')
}
11 changes: 11 additions & 0 deletions packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
watermarks: this.options.watermarks,
})

if (hasTerminalReporter(this.options.reporter))
this.ctx.logger.log(c.blue(' % ') + c.dim('Coverage report from ') + c.yellow(this.name))

for (const reporter of this.options.reporter) {
reports.create(reporter[0], {
skipFull: this.options.skipFull,
Expand Down Expand Up @@ -295,3 +298,11 @@ function normalizeTransformResults(fetchCaches: Map<string, { result: FetchResul

return normalized
}

function hasTerminalReporter(reporters: Options['reporter']) {
return reporters.some(([reporter]) =>
reporter === 'text'
|| reporter === 'text-summary'
|| reporter === 'text-lcov'
|| reporter === 'teamcity')
}
4 changes: 1 addition & 3 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,8 @@ export class Vitest {
if (!this.config.coverage.reportOnFailure && this.state.getCountOfFailedTests() > 0)
return

if (this.coverageProvider) {
this.logger.log(c.blue(' % ') + c.dim('Coverage report from ') + c.yellow(this.coverageProvider.name))
if (this.coverageProvider)
await this.coverageProvider.reportCoverage({ allTestsRun })
}
}

async close() {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f04386

Please sign in to comment.