|
| 1 | +import { expect, test, vi } from 'vitest' |
| 2 | +import { configDefaults } from 'vitest/config' |
| 3 | +import V8Provider from '@vitest/coverage-v8' |
| 4 | +import packageJson from '@vitest/coverage-v8/package.json' |
| 5 | +import IstanbulProvider from '@vitest/coverage-istanbul' |
| 6 | +import stripAnsi from 'strip-ansi' |
| 7 | + |
| 8 | +const version = packageJson.version |
| 9 | + |
| 10 | +test('v8 provider logs warning if versions do not match', async () => { |
| 11 | + const provider = await V8Provider.getProvider() |
| 12 | + const warn = vi.fn() |
| 13 | + |
| 14 | + provider.initialize({ |
| 15 | + version: '1.0.0', |
| 16 | + logger: { warn }, |
| 17 | + config: configDefaults, |
| 18 | + } as any) |
| 19 | + |
| 20 | + expect(warn).toHaveBeenCalled() |
| 21 | + |
| 22 | + const message = warn.mock.calls[0][0] |
| 23 | + |
| 24 | + expect(stripAnsi(message)).toMatchInlineSnapshot(` |
| 25 | + "Loaded vitest@1.0.0 and @vitest/coverage-v8@${version} . |
| 26 | + Running mixed versions is not supported and may lead into bugs |
| 27 | + Update your dependencies and make sure the versions match." |
| 28 | + `) |
| 29 | +}) |
| 30 | + |
| 31 | +test('istanbul provider logs warning if versions do not match', async () => { |
| 32 | + const provider = await IstanbulProvider.getProvider() |
| 33 | + const warn = vi.fn() |
| 34 | + |
| 35 | + provider.initialize({ |
| 36 | + version: '1.0.0', |
| 37 | + logger: { warn }, |
| 38 | + config: configDefaults, |
| 39 | + } as any) |
| 40 | + |
| 41 | + expect(warn).toHaveBeenCalled() |
| 42 | + |
| 43 | + const message = warn.mock.calls[0][0] |
| 44 | + |
| 45 | + expect(stripAnsi(message)).toMatchInlineSnapshot(` |
| 46 | + "Loaded vitest@1.0.0 and @vitest/coverage-istanbul@${version} . |
| 47 | + Running mixed versions is not supported and may lead into bugs |
| 48 | + Update your dependencies and make sure the versions match." |
| 49 | + `) |
| 50 | +}) |
0 commit comments