From 7802857518761e479d4ef9de6328d0e879c5dad8 Mon Sep 17 00:00:00 2001 From: AriPerkkio Date: Tue, 9 May 2023 13:12:00 +0300 Subject: [PATCH] test: add test case for #3131 --- test/config/package.json | 2 +- test/config/test/failures.test.ts | 14 ++++++++++++++ test/config/test/utils.ts | 7 ++++++- test/config/vitest.config.ts | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/test/config/package.json b/test/config/package.json index 2bde0e50bbe7..56c95551587d 100644 --- a/test/config/package.json +++ b/test/config/package.json @@ -2,7 +2,7 @@ "name": "@vitest/test-config", "private": true, "scripts": { - "test": "vitest run test/**" + "test": "vitest run" }, "devDependencies": { "execa": "^7.0.0", diff --git a/test/config/test/failures.test.ts b/test/config/test/failures.test.ts index 5abde7b08cb7..0dcfcd0f9032 100644 --- a/test/config/test/failures.test.ts +++ b/test/config/test/failures.test.ts @@ -1,4 +1,5 @@ import { expect, test } from 'vitest' +import { version } from 'vitest/package.json' import { runVitest } from './utils' @@ -57,3 +58,16 @@ test('boolean browser flag without dot notation, with more dot notation options' expect(error).toMatch('Error: A boolean argument "--browser" was used with dot notation arguments "--browser.name".') expect(error).toMatch('Please specify the "--browser" argument with dot notation as well: "--browser.enabled"') }) + +test('version number is printed when coverage provider fails to load', async () => { + const { error, output } = await runVitest('run', [ + '--coverage.enabled', + '--coverage.provider', + 'custom', + '--coverage.customProviderModule', + './non-existing-module.ts', + ]) + + expect(output).toMatch(`RUN v${version}`) + expect(error).toMatch('Error: Failed to load custom CoverageProviderModule from ./non-existing-module.ts') +}) diff --git a/test/config/test/utils.ts b/test/config/test/utils.ts index 51e8b4922494..775fd4ce91ed 100644 --- a/test/config/test/utils.ts +++ b/test/config/test/utils.ts @@ -4,6 +4,11 @@ import stripAnsi from 'strip-ansi' export async function runVitest(mode: 'run' | 'watch', cliArguments: string[]) { const subprocess = execa('vitest', [mode, 'fixtures/test/', ...cliArguments]) let error = '' + let output = '' + + subprocess.stdout?.on('data', (data) => { + output += stripAnsi(data.toString()) + }) subprocess.stderr?.on('data', (data) => { error += stripAnsi(data.toString()) @@ -14,5 +19,5 @@ export async function runVitest(mode: 'run' | 'watch', cliArguments: string[]) { await new Promise(resolve => subprocess.on('exit', resolve)) - return { error } + return { output, error } } diff --git a/test/config/vitest.config.ts b/test/config/vitest.config.ts index a3f5c3ce3f00..8d362f825f92 100644 --- a/test/config/vitest.config.ts +++ b/test/config/vitest.config.ts @@ -2,6 +2,7 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { + include: ['test/**.test.ts'], testTimeout: 60_000, chaiConfig: { truncateThreshold: 999,