Skip to content

Commit

Permalink
fix(coverage): c8 to log warning when run in Stackblitz (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Jan 23, 2023
1 parent 482b72f commit b6c41ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/coverage-c8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
},
"dependencies": {
"c8": "^7.12.0",
"picocolors": "^1.0.0",
"std-env": "^3.3.1",
"vitest": "workspace:*"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions packages/coverage-c8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import _url from 'url'
import type { Profiler } from 'inspector'
import { takeCoverage } from 'v8'
import { extname, resolve } from 'pathe'
import c from 'picocolors'
import { provider } from 'std-env'
import type { RawSourceMap } from 'vite-node'
import { coverageConfigDefaults } from 'vitest/config'
// eslint-disable-next-line no-restricted-imports
Expand Down Expand Up @@ -52,6 +54,9 @@ export class C8CoverageProvider implements CoverageProvider {
async reportCoverage({ allTestsRun }: ReportContext = {}) {
takeCoverage()

if (provider === 'stackblitz')
this.ctx.logger.log(c.blue(' % ') + c.yellow('@vitest/coverage-c8 does not work on Stackblitz. Report will be empty.'))

const options: ConstructorParameters<typeof Report>[0] = {
...this.options,
all: this.options.all && allTestsRun,
Expand Down
4 changes: 4 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 b6c41ca

Please sign in to comment.