|
| 1 | +import { expect } from 'vitest' |
| 2 | +import { isV8Provider, readCoverageMap, runVitest, test } from '../utils' |
| 3 | + |
| 4 | +test('in-source tests work', async () => { |
| 5 | + const { stdout } = await runVitest({ |
| 6 | + include: [], |
| 7 | + includeSource: ['fixtures/src/in-source.ts'], |
| 8 | + coverage: { all: false, reporter: 'json' }, |
| 9 | + }) |
| 10 | + |
| 11 | + expect(stdout).toContain('in source test running add function') |
| 12 | + |
| 13 | + const coverageMap = await readCoverageMap() |
| 14 | + const files = coverageMap.files() |
| 15 | + |
| 16 | + expect(files).toMatchInlineSnapshot(` |
| 17 | + [ |
| 18 | + "<process-cwd>/fixtures/src/in-source.ts", |
| 19 | + ] |
| 20 | + `) |
| 21 | + |
| 22 | + const fileCoverage = coverageMap.fileCoverageFor('<process-cwd>/fixtures/src/in-source.ts') |
| 23 | + |
| 24 | + // If-branch is not taken - makes sure source maps are correct in in-source testing too |
| 25 | + expect(fileCoverage.getUncoveredLines()).toContain('5') |
| 26 | + |
| 27 | + if (isV8Provider()) { |
| 28 | + expect(fileCoverage).toMatchInlineSnapshot(` |
| 29 | + { |
| 30 | + "branches": "2/4 (50%)", |
| 31 | + "functions": "1/1 (100%)", |
| 32 | + "lines": "10/12 (83.33%)", |
| 33 | + "statements": "10/12 (83.33%)", |
| 34 | + } |
| 35 | + `) |
| 36 | + } |
| 37 | + else { |
| 38 | + expect(fileCoverage).toMatchInlineSnapshot(` |
| 39 | + { |
| 40 | + "branches": "3/6 (50%)", |
| 41 | + "functions": "2/2 (100%)", |
| 42 | + "lines": "6/7 (85.71%)", |
| 43 | + "statements": "6/7 (85.71%)", |
| 44 | + } |
| 45 | + `) |
| 46 | + } |
| 47 | +}) |
0 commit comments