diff --git a/packages/coverage-v8/package.json b/packages/coverage-v8/package.json index 78f1e4b92f5d..1e594818d4a1 100644 --- a/packages/coverage-v8/package.json +++ b/packages/coverage-v8/package.json @@ -54,7 +54,6 @@ "magic-string": "^0.30.10", "magicast": "^0.3.4", "std-env": "^3.7.0", - "strip-literal": "^2.1.0", "test-exclude": "^7.0.1", "tinyrainbow": "^1.2.0" }, diff --git a/packages/coverage-v8/src/provider.ts b/packages/coverage-v8/src/provider.ts index 8b032e72a749..ca038ed47902 100644 --- a/packages/coverage-v8/src/provider.ts +++ b/packages/coverage-v8/src/provider.ts @@ -19,7 +19,6 @@ import remapping from '@ampproject/remapping' import { normalize, resolve } from 'pathe' import c from 'tinyrainbow' import { provider } from 'std-env' -import { stripLiteral } from 'strip-literal' import createDebug from 'debug' import { cleanUrl } from 'vite-node/utils' import type { EncodedSourceMap, FetchResult } from 'vite-node' @@ -391,16 +390,11 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage const coverages = await Promise.all( chunk.map(async (filename) => { - const { originalSource, source } = await this.getSources( + const { originalSource } = await this.getSources( filename.href, transformResults, ) - // Ignore empty files, e.g. files that contain only typescript types and no runtime code - if (source && stripLiteral(source).trim() === '') { - return null - } - const coverage = { url: filename.href, scriptId: '0', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f2b6d6f1b296..7bbcde7fd05c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -572,9 +572,6 @@ importers: std-env: specifier: ^3.7.0 version: 3.7.0 - strip-literal: - specifier: ^2.1.0 - version: 2.1.0 test-exclude: specifier: ^7.0.1 version: 7.0.1 diff --git a/test/coverage-test/test/empty-lines.v8.test.ts b/test/coverage-test/test/empty-lines.v8.test.ts index c6b3a2f6d8a2..7c55590327dc 100644 --- a/test/coverage-test/test/empty-lines.v8.test.ts +++ b/test/coverage-test/test/empty-lines.v8.test.ts @@ -12,7 +12,6 @@ type LineCoverage = Record describe('include empty lines', () => { let coveredFileLines: LineCoverage let uncoveredFileLines: LineCoverage - let files: string[] beforeAll(async () => { await runVitest({ @@ -28,16 +27,7 @@ describe('include empty lines', () => { }, }) - ;({ coveredFileLines, uncoveredFileLines, files } = await readCoverage()) - }) - - test('file containing only types is ignored', () => { - expect(files).toMatchInlineSnapshot(` - [ - "/fixtures/src/empty-lines.ts", - "/fixtures/src/untested-file.ts", - ] - `) + ;({ coveredFileLines, uncoveredFileLines } = await readCoverage()) }) test('lines are included', async () => { @@ -64,7 +54,7 @@ describe('include empty lines', () => { describe('ignore empty lines', () => { let coveredFileLines: LineCoverage let uncoveredFileLines: LineCoverage - let files: string[] + let typesOnlyFileLines: LineCoverage beforeAll(async () => { await runVitest({ @@ -79,16 +69,13 @@ describe('ignore empty lines', () => { }, }) - ;({ coveredFileLines, uncoveredFileLines, files } = await readCoverage()) + ;({ coveredFileLines, uncoveredFileLines, typesOnlyFileLines } = await readCoverage()) }) - test('file containing only types is ignored', () => { - expect(files).toMatchInlineSnapshot(` - [ - "/fixtures/src/empty-lines.ts", - "/fixtures/src/untested-file.ts", - ] - `) + test('file containing only types has no uncovered lines', () => { + expect(typesOnlyFileLines[1]).toBe(undefined) + expect(typesOnlyFileLines[2]).toBe(undefined) + expect(typesOnlyFileLines[3]).toBe(undefined) }) test('empty lines are ignored', async () => { @@ -184,12 +171,12 @@ coverageTest('cover some lines', () => { async function readCoverage() { const coverageMap = await readCoverageMap() - const files = coverageMap.files() const coveredFileLines = coverageMap.fileCoverageFor('/fixtures/src/empty-lines.ts').getLineCoverage() as LineCoverage const uncoveredFileLines = coverageMap.fileCoverageFor('/fixtures/src/untested-file.ts').getLineCoverage() as LineCoverage + const typesOnlyFileLines = coverageMap.fileCoverageFor('/fixtures/src/types-only.ts').getLineCoverage() as LineCoverage - return { coveredFileLines, uncoveredFileLines, files } + return { coveredFileLines, uncoveredFileLines, typesOnlyFileLines } } function range(count: number, options: { base: number } = { base: 1 }) {