Skip to content

Commit 0c3be6f

Browse files
authored
fix(coverage): ignore SCSS in browser mode (#8161)
1 parent bd2c481 commit 0c3be6f

File tree

7 files changed

+318
-68
lines changed

7 files changed

+318
-68
lines changed

packages/browser/src/node/providers/playwright.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
} from 'vitest/node'
2121
import { createManualModuleSource } from '@vitest/mocker/node'
2222
import c from 'tinyrainbow'
23-
import { createDebugger } from 'vitest/node'
23+
import { createDebugger, isCSSRequest } from 'vitest/node'
2424

2525
const debug = createDebugger('vitest:browser:playwright')
2626

@@ -471,10 +471,8 @@ function genSourceMapUrl(map: SourceMap | string): string {
471471
return `data:application/json;base64,${Buffer.from(map).toString('base64')}`
472472
}
473473

474-
const CSS_LANGS_RE
475-
= /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
476474
const directRequestRE = /[?&]direct\b/
477475

478476
function isDirectCSSRequest(request: string): boolean {
479-
return CSS_LANGS_RE.test(request) && directRequestRE.test(request)
477+
return isCSSRequest(request) && directRequestRE.test(request)
480478
}

packages/coverage-istanbul/src/provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { resolve } from 'pathe'
1616
import TestExclude from 'test-exclude'
1717
import c from 'tinyrainbow'
1818
import { BaseCoverageProvider } from 'vitest/coverage'
19+
import { isCSSRequest } from 'vitest/node'
1920

2021
import { version } from '../package.json' with { type: 'json' }
2122
import { COVERAGE_STORE_KEY } from './constants'
@@ -64,7 +65,7 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider<ResolvedCover
6465
// Istanbul/babel cannot instrument CSS - e.g. Vue imports end up here.
6566
// File extension itself is .vue, but it contains CSS.
6667
// e.g. "Example.vue?vue&type=style&index=0&scoped=f7f04e08&lang.css"
67-
if (id.endsWith('.css')) {
68+
if (isCSSRequest(id)) {
6869
return
6970
}
7071

packages/vitest/src/public/node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export type { SerializedError } from '@vitest/utils'
168168

169169
export {
170170
esbuildVersion,
171+
isCSSRequest,
171172
isFileServingAllowed,
172173
parseAst,
173174
parseAstAsync,

pnpm-lock.yaml

Lines changed: 302 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/core/test/exports.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ it('exports snapshot', async ({ skip, task }) => {
103103
"esbuildVersion": "string",
104104
"generateFileHash": "function",
105105
"getFilePoolName": "function",
106+
"isCSSRequest": "function",
106107
"isFileServingAllowed": "function",
107108
"isValidApiRequest": "function",
108109
"parseAst": "function",
@@ -259,6 +260,7 @@ it('exports snapshot', async ({ skip, task }) => {
259260
"esbuildVersion": "string",
260261
"generateFileHash": "function",
261262
"getFilePoolName": "function",
263+
"isCSSRequest": "function",
262264
"isFileServingAllowed": "function",
263265
"isValidApiRequest": "function",
264266
"parseAst": "function",

test/coverage-test/fixtures/src/Vue/Hello.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ defineExpose(props)
1515
x1
1616
</button>
1717
</template>
18+
19+
<!-- Style block triggers a specific condition where sourcemaps used to break randomly -->
20+
<!-- https://github.com/vitest-dev/vitest/issues/8154 -->
21+
<style lang="scss">
22+
body {
23+
background-color: #FFF;
24+
}
25+
</style>

test/coverage-test/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"istanbul-lib-report": "catalog:",
2222
"magic-string": "^0.30.17",
2323
"magicast": "^0.3.5",
24+
"sass-embedded": "^1.89.2",
2425
"unplugin-swc": "^1.5.4",
2526
"vite": "latest",
2627
"vitest": "workspace:*",

0 commit comments

Comments
 (0)