From 708051319da127e6aaab24c81fb8bf795260e727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Sun, 23 Jun 2024 18:34:04 +0300 Subject: [PATCH] fix(coverage): pass thresholds errors to `stderr` of `startVitest()` (#5954) --- packages/coverage-istanbul/src/provider.ts | 1 + packages/coverage-v8/src/provider.ts | 1 + packages/vitest/src/utils/coverage.ts | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/coverage-istanbul/src/provider.ts b/packages/coverage-istanbul/src/provider.ts index 0311e0729bef..5bc72843c51d 100644 --- a/packages/coverage-istanbul/src/provider.ts +++ b/packages/coverage-istanbul/src/provider.ts @@ -336,6 +336,7 @@ export class IstanbulCoverageProvider this.checkThresholds({ thresholds: resolvedThresholds, perFile: this.options.thresholds.perFile, + onError: error => this.ctx.logger.error(error), }) if (this.options.thresholds.autoUpdate && allTestsRun) { diff --git a/packages/coverage-v8/src/provider.ts b/packages/coverage-v8/src/provider.ts index c067b3f512fe..19a88e71e56b 100644 --- a/packages/coverage-v8/src/provider.ts +++ b/packages/coverage-v8/src/provider.ts @@ -324,6 +324,7 @@ export class V8CoverageProvider this.checkThresholds({ thresholds: resolvedThresholds, perFile: this.options.thresholds.perFile, + onError: error => this.ctx.logger.error(error), }) if (this.options.thresholds.autoUpdate && allTestsRun) { diff --git a/packages/vitest/src/utils/coverage.ts b/packages/vitest/src/utils/coverage.ts index 49510a1565f4..e5755c330373 100644 --- a/packages/vitest/src/utils/coverage.ts +++ b/packages/vitest/src/utils/coverage.ts @@ -95,9 +95,11 @@ export class BaseCoverageProvider { checkThresholds({ thresholds: allThresholds, perFile, + onError, }: { thresholds: ResolvedThreshold[] perFile?: boolean + onError: (error: string) => void }) { for (const { coverageMap, thresholds, name } of allThresholds) { if ( @@ -154,7 +156,7 @@ export class BaseCoverageProvider { )}` } - console.error(errorMessage) + onError(errorMessage) } } }