From 73426093aca6e83cb455633bdf3dc934d8cda3fd Mon Sep 17 00:00:00 2001 From: AriPerkkio Date: Sun, 5 Feb 2023 15:26:04 +0200 Subject: [PATCH] test: simplify coverage test setup --- test/coverage-test/package.json | 2 +- test/coverage-test/testing.mjs | 48 +++++++---------------------- test/coverage-test/vitest.config.ts | 7 +++-- 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/test/coverage-test/package.json b/test/coverage-test/package.json index 90fd498cbe73..32142f1da245 100644 --- a/test/coverage-test/package.json +++ b/test/coverage-test/package.json @@ -2,7 +2,7 @@ "name": "@vitest/test-coverage", "private": true, "scripts": { - "test": "pnpm run test:c8 && pnpm run test:istanbul && pnpm run test:types", + "test": "pnpm test:c8 && pnpm test:istanbul && pnpm test:types", "test:c8": "node ./testing.mjs --provider c8", "test:istanbul": "node ./testing.mjs --provider istanbul", "test:types": "vitest typecheck --run" diff --git a/test/coverage-test/testing.mjs b/test/coverage-test/testing.mjs index f419f1acbcab..906b720ba65c 100644 --- a/test/coverage-test/testing.mjs +++ b/test/coverage-test/testing.mjs @@ -3,13 +3,14 @@ import { startVitest } from 'vitest/node' // Set this to true when intentionally updating the snapshots const UPDATE_SNAPSHOTS = false -const provider = getArgument('--provider') +const provider = process.argv[1 + process.argv.indexOf('--provider')] const configs = [ // Run test cases. Generates coverage report. ['test/', { include: ['test/*.test.*'], exclude: ['coverage-report-tests/**/*'], + coverage: { enabled: true }, }], // Run tests for checking coverage report contents. @@ -22,42 +23,15 @@ const configs = [ }], ] -runTests() +for (const threads of [true, false]) { + for (const [directory, config] of configs) { + await startVitest('test', [directory], { + ...config, + update: UPDATE_SNAPSHOTS, + threads, + }) -async function runTests() { - for (const threads of [true, false]) { - for (const [directory, config] of configs) { - await startVitest('test', [directory], { - run: true, - update: UPDATE_SNAPSHOTS, - ...config, - threads, - coverage: { - include: ['src/**'], - provider, - ...config.coverage, - }, - }) - - if (process.exitCode) - process.exit() - } + if (process.exitCode) + process.exit() } - - process.exit(0) -} - -function getArgument(name) { - const args = process.argv - const index = args.indexOf(name) - - if (index === -1) - throw new Error(`Missing argument ${name}, received ${args}`) - - const value = args[index + 1] - - if (!value) - throw new Error(`Missing value of ${name}, received ${args}`) - - return value } diff --git a/test/coverage-test/vitest.config.ts b/test/coverage-test/vitest.config.ts index 04ecdaa76505..218d0d19e5fb 100644 --- a/test/coverage-test/vitest.config.ts +++ b/test/coverage-test/vitest.config.ts @@ -2,6 +2,8 @@ import { resolve } from 'pathe' import { defineConfig } from 'vitest/config' import vue from '@vitejs/plugin-vue' +const provider = process.argv[1 + process.argv.indexOf('--provider')] + export default defineConfig({ plugins: [ vue(), @@ -10,9 +12,10 @@ export default defineConfig({ MY_CONSTANT: '"my constant"', }, test: { - reporters: 'verbose', + watch: false, coverage: { - enabled: true, + provider: provider as any, + include: ['src/**'], clean: true, all: true, reporter: ['html', 'text', 'lcov', 'json'],