|
| 1 | +import { expect } from 'vitest' |
| 2 | +import { coverageTest, normalizeURL, readCoverageMap, runVitest, test } from '../utils.js' |
| 3 | +import * as transpiled from '../fixtures/src/pre-bundle/bundle.js' |
| 4 | + |
| 5 | +test('{ excludeAfterRemap: true } should exclude files that come up after remapping', async () => { |
| 6 | + await runVitest({ |
| 7 | + include: [normalizeURL(import.meta.url)], |
| 8 | + coverage: { |
| 9 | + include: ['fixtures/src/**'], |
| 10 | + exclude: ['fixtures/src/pre-bundle/second.ts'], |
| 11 | + excludeAfterRemap: true, |
| 12 | + reporter: 'json', |
| 13 | + all: false, |
| 14 | + }, |
| 15 | + }) |
| 16 | + |
| 17 | + const coverageMap = await readCoverageMap() |
| 18 | + const files = coverageMap.files() |
| 19 | + |
| 20 | + expect(files).toMatchInlineSnapshot(` |
| 21 | + [ |
| 22 | + "<process-cwd>/fixtures/src/pre-bundle/first.ts", |
| 23 | + ] |
| 24 | + `) |
| 25 | +}) |
| 26 | + |
| 27 | +test('{ excludeAfterRemap: false } should not exclude files that come up after remapping', async () => { |
| 28 | + await runVitest({ |
| 29 | + include: [normalizeURL(import.meta.url)], |
| 30 | + coverage: { |
| 31 | + include: ['fixtures/src/**'], |
| 32 | + exclude: ['fixtures/src/pre-bundle/second.ts'], |
| 33 | + reporter: 'json', |
| 34 | + all: false, |
| 35 | + }, |
| 36 | + }) |
| 37 | + |
| 38 | + const coverageMap = await readCoverageMap() |
| 39 | + const files = coverageMap.files() |
| 40 | + |
| 41 | + expect(files).toMatchInlineSnapshot(` |
| 42 | + [ |
| 43 | + "<process-cwd>/fixtures/src/pre-bundle/first.ts", |
| 44 | + "<process-cwd>/fixtures/src/pre-bundle/second.ts", |
| 45 | + ] |
| 46 | + `) |
| 47 | +}) |
| 48 | + |
| 49 | +test('{ excludeAfterRemap: true } should exclude uncovered files that come up after remapping', async () => { |
| 50 | + await runVitest({ |
| 51 | + include: ['fixtures/test/math.test.ts'], |
| 52 | + coverage: { |
| 53 | + include: ['fixtures/src/pre-bundle/**'], |
| 54 | + exclude: ['fixtures/src/pre-bundle/second.ts'], |
| 55 | + excludeAfterRemap: true, |
| 56 | + reporter: 'json', |
| 57 | + all: true, |
| 58 | + }, |
| 59 | + }) |
| 60 | + |
| 61 | + const coverageMap = await readCoverageMap() |
| 62 | + const files = coverageMap.files() |
| 63 | + |
| 64 | + expect(files).contains('<process-cwd>/fixtures/src/pre-bundle/first.ts') |
| 65 | + expect(files).not.contains('<process-cwd>/fixtures/src/pre-bundle/second.ts') |
| 66 | +}) |
| 67 | + |
| 68 | +coverageTest('run bundled sources', () => { |
| 69 | + expect(transpiled.first.covered()).toBe('First') |
| 70 | + expect(transpiled.second.covered()).toBe('Second') |
| 71 | +}) |
0 commit comments