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: convert string coverage reporters to array #1860



Copy link

Fixes issue where coverage: { reporters: 'text' } crashes coverage report generation. String reporter is converted into array of characters and looped here:

for (const reporter of this.options.reporter) {

C8 is already converting string reporters into an array before looping them. Applied the same logic to istanbul.

resolved.reporter = Array.isArray(resolved.reporter) ? resolved.reporter : [resolved.reporter]

Error seen with string reporters:

export default defineConfig({
    test: {
        coverage: {
            provider: 'istanbul',
            enabled: true,
            reporter: 'text'
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
 ❯ Function.Module._resolveFilename node:internal/modules/cjs/loader:933:15
Error: Cannot find module 't'
Require stack:
- /workspaces/vitest/node_modules/.pnpm/istanbul-reports@3.1.5/node_modules/istanbul-reports/index.js
 ❯ Function.Module._load node:internal/modules/cjs/loader:778:27
 ❯ Module.require node:internal/modules/cjs/loader:1005:19
 ❯ require node:internal/modules/cjs/helpers:102:18
 ❯ Object.create ../vitest/node_modules/.pnpm/istanbul-reports@3.1.5/node_modules/istanbul-reports/index.js:19:20
 ❯ IstanbulCoverageProvider.reportCoverage ../vitest/packages/coverage-istanbul/dist/provider-c0b24cef.js:253:15
 ❯ Vitest.start ../vitest/packages/vitest/dist/chunk-vite-node-externalize.1a5aabf5.mjs:9553:7
 ❯ startVitest ../vitest/packages/vitest/dist/chunk-vite-node-externalize.1a5aabf5.mjs:10322:5
 ❯ start ../vitest/packages/vitest/dist/cli.mjs:668:9
 ❯ ../vitest/packages/vitest/dist/cli.mjs:664:3

Serialized Error: {
  "code": "MODULE_NOT_FOUND",
  "requireStack": [

@AriPerkkio AriPerkkio marked this pull request as ready for review August 16, 2022 09:19
@sheremet-va sheremet-va changed the title fix: convert string reporters to array fix: convert string coverage reporters to array Aug 17, 2022
@sheremet-va sheremet-va merged commit e21c78c into vitest-dev:main Aug 17, 2022
@AriPerkkio AriPerkkio deleted the fix/instanbul-reporters-string branch August 17, 2022 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants