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(coverage): prevent c8 from crashing on invalid sourcemaps #2634

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/coverage-c8/src/provider.ts
Expand Up @@ -86,6 +86,7 @@ export class C8CoverageProvider implements CoverageProvider {
entry.map.mappings.length > 0
&& entry.map.sourcesContent
&& entry.map.sourcesContent.length > 0
&& entry.map.sourcesContent[0]
&& entry.map.sourcesContent[0].length > 0
)
}) as SourceMapMeta[]
Expand Down
10 changes: 10 additions & 0 deletions test/coverage-test/test/no-esbuild-transform.test.js
@@ -0,0 +1,10 @@
import { expect, test, vi } from 'vitest'
import { add } from '../src/utils'

vi.mock('../src/utils', async () => ({
add: vi.fn().mockReturnValue('mocked'),
}))

test('mocking in Javascript test should not break sourcemaps', () => {
expect(add(1, 2)).toBe('mocked')
})
2 changes: 1 addition & 1 deletion test/coverage-test/testing.mjs
Expand Up @@ -8,7 +8,7 @@ const provider = getArgument('--provider')
const configs = [
// Run test cases. Generates coverage report.
['test/', {
include: ['test/*.test.ts'],
include: ['test/*.test.*'],
exclude: ['coverage-report-tests/**/*'],
}],

Expand Down