diff --git a/test/coverage-test/coverage-report-tests/__snapshots__/custom.report.test.ts.snap b/test/coverage-test/coverage-report-tests/__snapshots__/custom.report.test.ts.snap index e3973b7d00c1..749432a0c148 100644 --- a/test/coverage-test/coverage-report-tests/__snapshots__/custom.report.test.ts.snap +++ b/test/coverage-test/coverage-report-tests/__snapshots__/custom.report.test.ts.snap @@ -23,6 +23,7 @@ exports[`custom json report 1`] = ` "/src/importEnv.ts", "/src/index.mts", "/src/multi-suite.ts", + "/src/process-env.ts", "/src/utils.ts", ], } diff --git a/test/coverage-test/coverage-report-tests/__snapshots__/istanbul.report.test.ts.snap b/test/coverage-test/coverage-report-tests/__snapshots__/istanbul.report.test.ts.snap index 9af54d6026c4..c20d2a0a7530 100644 --- a/test/coverage-test/coverage-report-tests/__snapshots__/istanbul.report.test.ts.snap +++ b/test/coverage-test/coverage-report-tests/__snapshots__/istanbul.report.test.ts.snap @@ -1425,6 +1425,54 @@ exports[`istanbul json report 1`] = ` }, }, }, + "/src/process-env.ts": { + "b": {}, + "branchMap": {}, + "f": { + "0": 1, + }, + "fnMap": { + "0": { + "decl": { + "end": { + "column": 29, + "line": 1, + }, + "start": { + "column": 16, + "line": 1, + }, + }, + "loc": { + "end": { + "column": null, + "line": 3, + }, + "start": { + "column": 29, + "line": 1, + }, + }, + "name": "getNodeEnv", + }, + }, + "path": "/src/process-env.ts", + "s": { + "0": 1, + }, + "statementMap": { + "0": { + "end": { + "column": null, + "line": 2, + }, + "start": { + "column": 2, + "line": 2, + }, + }, + }, + }, "/src/untested-file.ts": { "b": { "0": [ diff --git a/test/coverage-test/coverage-report-tests/__snapshots__/v8.report.test.ts.snap b/test/coverage-test/coverage-report-tests/__snapshots__/v8.report.test.ts.snap index 08c1cc21d00e..25a12fb02115 100644 --- a/test/coverage-test/coverage-report-tests/__snapshots__/v8.report.test.ts.snap +++ b/test/coverage-test/coverage-report-tests/__snapshots__/v8.report.test.ts.snap @@ -3528,6 +3528,109 @@ exports[`v8 json report 1`] = ` }, }, }, + "/src/process-env.ts": { + "all": false, + "b": { + "0": [ + 1, + ], + }, + "branchMap": { + "0": { + "line": 1, + "loc": { + "end": { + "column": 1, + "line": 3, + }, + "start": { + "column": 7, + "line": 1, + }, + }, + "locations": [ + { + "end": { + "column": 1, + "line": 3, + }, + "start": { + "column": 7, + "line": 1, + }, + }, + ], + "type": "branch", + }, + }, + "f": { + "0": 1, + }, + "fnMap": { + "0": { + "decl": { + "end": { + "column": 1, + "line": 3, + }, + "start": { + "column": 7, + "line": 1, + }, + }, + "line": 1, + "loc": { + "end": { + "column": 1, + "line": 3, + }, + "start": { + "column": 7, + "line": 1, + }, + }, + "name": "getNodeEnv", + }, + }, + "path": "/src/process-env.ts", + "s": { + "0": 1, + "1": 1, + "2": 1, + }, + "statementMap": { + "0": { + "end": { + "column": 30, + "line": 1, + }, + "start": { + "column": 0, + "line": 1, + }, + }, + "1": { + "end": { + "column": 29, + "line": 2, + }, + "start": { + "column": 0, + "line": 2, + }, + }, + "2": { + "end": { + "column": 1, + "line": 3, + }, + "start": { + "column": 0, + "line": 3, + }, + }, + }, + }, "/src/untested-file.ts": { "all": true, "b": { diff --git a/test/coverage-test/coverage-report-tests/istanbul.report.test.ts b/test/coverage-test/coverage-report-tests/istanbul.report.test.ts index 38402f18e75e..e8602be61d42 100644 --- a/test/coverage-test/coverage-report-tests/istanbul.report.test.ts +++ b/test/coverage-test/coverage-report-tests/istanbul.report.test.ts @@ -2,6 +2,8 @@ * Istanbul coverage provider specific test cases */ +import { resolve } from 'node:path' +import { readFileSync } from 'node:fs' import { expect, test } from 'vitest' import { readCoverageJson } from './utils' @@ -50,3 +52,11 @@ test('tests with multiple suites are covered', async () => { 1: 1, }) }) + +test('vite transforms should not show on coverage report', async () => { + const filePath = resolve('./coverage/src/process-env.ts.html') + const htmlContent = readFileSync(filePath, 'utf-8') + + // Actual source code + expect(htmlContent).toContain('process.env.NODE_ENV') +}) diff --git a/test/coverage-test/src/process-env.ts b/test/coverage-test/src/process-env.ts new file mode 100644 index 000000000000..c0abe95dd292 --- /dev/null +++ b/test/coverage-test/src/process-env.ts @@ -0,0 +1,3 @@ +export function getNodeEnv() { + return process.env.NODE_ENV +} diff --git a/test/coverage-test/test/jsdom.test.ts b/test/coverage-test/test/jsdom.test.ts new file mode 100644 index 000000000000..067daa96d0ba --- /dev/null +++ b/test/coverage-test/test/jsdom.test.ts @@ -0,0 +1,8 @@ +// @vitest-environment jsdom + +import { expect, test } from 'vitest' +import { getNodeEnv } from '../src/process-env' + +test('process.env works', () => { + expect(getNodeEnv()).toBe('test') +})