Skip to content

Commit

Permalink
fix(coverage): prevent c8 from crashing on invalid sourcemaps (#2634)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Jan 10, 2023
1 parent 9b8afb2 commit 0163dc8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/coverage-c8/src/provider.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit 0163dc8

Please sign in to comment.