Skip to content

Commit

Permalink
test: fix c8 coverage test
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 31, 2022
1 parent 46c7bc6 commit 37f4ca1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/coverage-c8/src/provider.ts
Expand Up @@ -58,7 +58,7 @@ export class C8CoverageProvider implements CoverageProvider {
if (!map)
return

const url = _url.pathToFileURL(file.replace(/\?(.*)/, '')).href
const url = _url.pathToFileURL(file.split('?')[0]).href

let code: string | undefined
try {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,5 +1,5 @@
import { expect, test } from 'vitest'
import { add } from '../../src/coverage-report/utils.js'
import { add } from '../../../src/coverage-report/utils.js'

test('add', () => {
expect(add(10, 15)).toBe(25)
Expand Down
16 changes: 8 additions & 8 deletions test/coverage-test/coverage-test/coverage.c8.test.ts
Expand Up @@ -28,15 +28,15 @@ test('coverage c8', async () => {
})

test('Should show coverage', async () => {
const stdout = await run('--config', 'vitest.config-c8-coverage.ts', '--coverage')
const stdout = await run('--config', 'vitest.config-c8-internal-coverage.ts', '--coverage')

// For Vue SFC and vue + ts files
expect(stdout).contain('not-SFC.ts')
expect(stdout).not.contain('not-SFC.ts?vue')
expect(stdout).contain('not-SFC.vue')
expect(stdout).contain('SFC.vue')
expect(stdout).toContain('not-SFC.ts')
expect(stdout).not.toContain('not-SFC.ts?vue')
expect(stdout).toContain('not-SFC.vue')
expect(stdout).toContain('SFC.vue')

// For ts and js files
expect(stdout).contain('math.ts')
expect(stdout).contain('utils.js')
}, 10000)
expect(stdout).toContain('math.ts')
expect(stdout).toContain('utils.js')
}, 30000)
1 change: 0 additions & 1 deletion test/coverage-test/vitest.config-c8-coverage.ts
Expand Up @@ -6,7 +6,6 @@ export default defineConfig({
test: {
include: [
'./coverage-test/*.c8.test.ts',
'./coverage-test/c8/**/*test.ts',
],
coverage: {
reporter: ['html', 'text', 'lcov'],
Expand Down
16 changes: 16 additions & 0 deletions test/coverage-test/vitest.config-c8-internal-coverage.ts
@@ -0,0 +1,16 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
plugins: [vue()],
test: {
include: [
'./coverage-test/c8/**/*test.{ts,js}',
],
coverage: {
reporter: ['html', 'text', 'lcov'],
include: ['src/**'],
extension: ['.ts', '.vue', '.js'],
},
},
})

0 comments on commit 37f4ca1

Please sign in to comment.