[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(coverage): istanbul to support import attributes (#6006)

authored by

Dylan Yang and committed by
GitHub
(Jul 1, 2024, 9:07 AM +0300) 2898a525 d066ba98

+64 -13
+18 -12
pnpm-lock.yaml
··· 499 499 500 500 packages/coverage-istanbul: 501 501 dependencies: 502 + '@istanbuljs/schema': 503 + specifier: ^0.1.3 504 + version: 0.1.3 502 505 debug: 503 506 specifier: ^4.3.5 504 507 version: 4.3.5 ··· 506 509 specifier: ^3.2.2 507 510 version: 3.2.2 508 511 istanbul-lib-instrument: 509 - specifier: ^6.0.2 510 - version: 6.0.2 512 + specifier: ^6.0.3 513 + version: 6.0.3 511 514 istanbul-lib-report: 512 515 specifier: ^3.0.1 513 516 version: 3.0.1 ··· 1762 1765 semver: 6.3.1 1763 1766 transitivePeerDependencies: 1764 1767 - supports-color 1768 + dev: true 1765 1769 1766 1770 /@babel/core@7.24.5: 1767 1771 resolution: {integrity: sha512-tVQRucExLQ02Boi4vdPp49svNGcfL2GhdTCT9aldhXgCJVAI21EtRfBettiuLUwce/7r6bFdgs6JFkcdTiFttA==} ··· 1807 1811 semver: 6.3.1 1808 1812 transitivePeerDependencies: 1809 1813 - supports-color 1810 - dev: true 1811 1814 1812 1815 /@babel/generator@7.24.5: 1813 1816 resolution: {integrity: sha512-x32i4hEXvr+iI0NEoEfDKzlemF8AmtOP8CcrRaEcpzysWuoEb1KknpcvMsHKPONoKZiDuItklgWhB18xEhr9PA==} ··· 1817 1820 '@jridgewell/gen-mapping': 0.3.5 1818 1821 '@jridgewell/trace-mapping': 0.3.25 1819 1822 jsesc: 2.5.2 1823 + dev: true 1820 1824 1821 1825 /@babel/generator@7.24.7: 1822 1826 resolution: {integrity: sha512-oipXieGC3i45Y1A41t4tAqpnEZWgB/lC6Ehh6+rOviR5XWpTtMmLN+fGjz9vOiNRt0p6RtO6DtD0pdU3vpqdSA==} ··· 1857 1861 browserslist: 4.23.0 1858 1862 lru-cache: 5.1.1 1859 1863 semver: 6.3.1 1864 + dev: true 1860 1865 1861 1866 /@babel/helper-compilation-targets@7.24.7: 1862 1867 resolution: {integrity: sha512-ctSdRHBi20qWOfy27RUb4Fhp07KSJ3sXcuSvTrXrc4aG8NSYDo1ici3Vhg9bg69y5bj0Mr1lh0aeEgTvc12rMg==} ··· 1867 1872 browserslist: 4.23.0 1868 1873 lru-cache: 5.1.1 1869 1874 semver: 6.3.1 1870 - dev: true 1871 1875 1872 1876 /@babel/helper-create-class-features-plugin@7.24.7(@babel/core@7.23.3): 1873 1877 resolution: {integrity: sha512-kTkaDl7c9vO80zeX1rJxnuRpEsD5tA81yh11X1gQo+PhSti3JS+7qeZo9U4RHobKRiFPKaGK3svUAeb8D0Q7eg==} ··· 2017 2021 '@babel/helper-validator-identifier': 7.24.7 2018 2022 transitivePeerDependencies: 2019 2023 - supports-color 2024 + dev: true 2020 2025 2021 2026 /@babel/helper-module-transforms@7.24.5(@babel/core@7.24.5): 2022 2027 resolution: {integrity: sha512-9GxeY8c2d2mdQUP1Dye0ks3VDyIMS98kt/llQ2nUId8IsWqTF0l1LkSX0/uP7l7MCDrzXS009Hyhe2gzTiGW8A==} ··· 2064 2069 '@babel/helper-validator-identifier': 7.24.7 2065 2070 transitivePeerDependencies: 2066 2071 - supports-color 2067 - dev: true 2068 2072 2069 2073 /@babel/helper-optimise-call-expression@7.24.7: 2070 2074 resolution: {integrity: sha512-jKiTsW2xmWwxT1ixIdfXUZp+P5yURx2suzLZr5Hi64rURpDYdMW0pv+Uf17EYk2Rd428Lx4tLsnjGJzYKDM/6A==} ··· 2194 2198 '@babel/types': 7.24.7 2195 2199 transitivePeerDependencies: 2196 2200 - supports-color 2201 + dev: true 2197 2202 2198 2203 /@babel/helpers@7.24.7: 2199 2204 resolution: {integrity: sha512-NlmJJtvcw72yRJRcnCmGvSi+3jDEg8qFu3z0AFoymmzLx5ERVWyzd9kVXr7Th9/8yIJi2Zc6av4Tqz3wFs8QWg==} ··· 2201 2206 dependencies: 2202 2207 '@babel/template': 7.24.7 2203 2208 '@babel/types': 7.24.7 2204 - dev: true 2205 2209 2206 2210 /@babel/highlight@7.24.7: 2207 2211 resolution: {integrity: sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==} ··· 2234 2238 hasBin: true 2235 2239 dependencies: 2236 2240 '@babel/types': 7.24.7 2241 + dev: true 2237 2242 2238 2243 /@babel/parser@7.24.7: 2239 2244 resolution: {integrity: sha512-9uUYRm6OqQrCqQdG1iCBwBPZgN8ciDBro2nIOFaiRz1/BCxaI7CNvQbDHvsArAC7Tw9Hda/B3U+6ui9u4HWXPw==} ··· 3291 3296 '@babel/code-frame': 7.24.7 3292 3297 '@babel/parser': 7.24.7 3293 3298 '@babel/types': 7.24.7 3299 + dev: true 3294 3300 3295 3301 /@babel/template@7.24.7: 3296 3302 resolution: {integrity: sha512-jYqfPrU9JTF0PmPy1tLYHW4Mp4KlgxJD9l2nP9fD6yT/ICi554DmrWBAEYpIelzjHf1msDP3PxJIRt/nFNfBig==} ··· 3316 3322 globals: 11.12.0 3317 3323 transitivePeerDependencies: 3318 3324 - supports-color 3325 + dev: true 3319 3326 3320 3327 /@babel/traverse@7.24.7: 3321 3328 resolution: {integrity: sha512-yb65Ed5S/QAcewNPh0nZczy9JdYXkkAbIsEo+P7BE7yO3txAY30Y/oPa3QkQ5It3xVG2kpKMg9MsdxZaO31uKA==} ··· 11123 11130 resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} 11124 11131 engines: {node: '>=8'} 11125 11132 11126 - /istanbul-lib-instrument@6.0.2: 11127 - resolution: {integrity: sha512-1WUsZ9R1lA0HtBSohTkm39WTPlNKSJ5iFk7UwqXkBLoHQT+hfqPsfsTDVuZdKGaBwn7din9bS7SsnoAr943hvw==} 11133 + /istanbul-lib-instrument@6.0.3: 11134 + resolution: {integrity: sha512-Vtgk7L/R2JHyyGW07spoFlB8/lpjiOLTjMdms6AFMraYt3BaJauod/NGrfnVG/y4Ix1JEuMRPDPEj2ua+zz1/Q==} 11128 11135 engines: {node: '>=10'} 11129 11136 dependencies: 11130 - '@babel/core': 7.24.4 11131 - '@babel/parser': 7.24.4 11137 + '@babel/core': 7.24.7 11138 + '@babel/parser': 7.24.7 11132 11139 '@istanbuljs/schema': 0.1.3 11133 11140 istanbul-lib-coverage: 3.2.2 11134 - semver: 7.6.0 11141 + semver: 7.6.2 11135 11142 transitivePeerDependencies: 11136 11143 - supports-color 11137 11144 dev: false ··· 14021 14028 resolution: {integrity: sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==} 14022 14029 engines: {node: '>=10'} 14023 14030 hasBin: true 14024 - dev: true 14025 14031 14026 14032 /send@0.18.0: 14027 14033 resolution: {integrity: sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==}
+2 -1
packages/coverage-istanbul/package.json
··· 44 44 "vitest": "workspace:*" 45 45 }, 46 46 "dependencies": { 47 + "@istanbuljs/schema": "^0.1.3", 47 48 "debug": "^4.3.5", 48 49 "istanbul-lib-coverage": "^3.2.2", 49 - "istanbul-lib-instrument": "^6.0.2", 50 + "istanbul-lib-instrument": "^6.0.3", 50 51 "istanbul-lib-report": "^3.0.1", 51 52 "istanbul-lib-source-maps": "^5.0.4", 52 53 "istanbul-reports": "^3.1.7",
+1
test/coverage-test/vitest.workspace.custom.ts
··· 67 67 68 68 // Other non-provider-specific tests that should be run on browser mode as well 69 69 '**/ignore-hints.test.ts', 70 + '**/import-attributes.test.ts', 70 71 '**/multi-suite.test.ts', 71 72 '**/setup-files.test.ts', 72 73 '**/results-snapshot.test.ts',
+9
packages/coverage-istanbul/src/provider.ts
··· 28 28 import libCoverage from 'istanbul-lib-coverage' 29 29 import libSourceMaps from 'istanbul-lib-source-maps' 30 30 import { type Instrumenter, createInstrumenter } from 'istanbul-lib-instrument' 31 + // @ts-expect-error @istanbuljs/schema has no type definitions 32 + import { defaults as istanbulDefaults } from '@istanbuljs/schema' 31 33 32 34 // @ts-expect-error missing types 33 35 import _TestExclude from 'test-exclude' ··· 116 118 coverageGlobalScope: 'globalThis', 117 119 coverageGlobalScopeFunc: false, 118 120 ignoreClassMethods: this.options.ignoreClassMethods, 121 + parserPlugins: [ 122 + ...istanbulDefaults.instrumenter.parserPlugins, 123 + ['importAttributes', { deprecatedAssertSyntax: true }], 124 + ], 125 + generatorOpts: { 126 + importAttributesKeyword: 'with', 127 + }, 119 128 }) 120 129 121 130 this.testExclude = new _TestExclude({
+18
test/coverage-test/test/import-attributes.test.ts
··· 1 + import { expect } from 'vitest' 2 + import { readCoverageMap, runVitest, test } from '../utils' 3 + 4 + test('import attributes work', async () => { 5 + await runVitest({ 6 + include: ['fixtures/test/import-attributes-fixture.test.ts'], 7 + coverage: { reporter: 'json', all: false }, 8 + }) 9 + 10 + const coverageMap = await readCoverageMap() 11 + const files = coverageMap.files() 12 + 13 + expect(files).toMatchInlineSnapshot(` 14 + [ 15 + "<process-cwd>/fixtures/src/json-data-import.ts", 16 + ] 17 + `) 18 + })
+5
test/coverage-test/fixtures/src/json-data-import.ts
··· 1 + import data from "./json-data.json" with { "type": "json" }; 2 + 3 + export function getJSON() { 4 + return data 5 + };
+4
test/coverage-test/fixtures/src/json-data.json
··· 1 + { 2 + "foo": false, 3 + "bar": "baz" 4 + }
+7
test/coverage-test/fixtures/test/import-attributes-fixture.test.ts
··· 1 + import { expect, test } from "vitest"; 2 + import {getJSON} from "../src/json-data-import"; 3 + import json from "../src/json-data.json"; 4 + 5 + test("JSON data", () => { 6 + expect(getJSON()).toEqual(json); 7 + });