From c65b65994d07a209482be528c84ec208dfbb3c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Wed, 15 May 2024 20:04:00 +0300 Subject: [PATCH] fix: clean up empty coverage reports directory --- .../option-tests/fixture.test.ts | 8 +++++++ test/coverage-test/testing-options.mjs | 21 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/coverage-test/option-tests/fixture.test.ts diff --git a/test/coverage-test/option-tests/fixture.test.ts b/test/coverage-test/option-tests/fixture.test.ts new file mode 100644 index 0000000000000..2121ecdf3a0f8 --- /dev/null +++ b/test/coverage-test/option-tests/fixture.test.ts @@ -0,0 +1,8 @@ +// Generic test fixture to generate some coverage + +import { test } from 'vitest' +import { add } from '../src/utils' + +test('cover some lines', () => { + add(1, 2) +}) diff --git a/test/coverage-test/testing-options.mjs b/test/coverage-test/testing-options.mjs index e806dd07dd5a4..690713f6d5556 100644 --- a/test/coverage-test/testing-options.mjs +++ b/test/coverage-test/testing-options.mjs @@ -1,4 +1,4 @@ -import { readFileSync, rmSync, writeFileSync } from 'node:fs' +import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs' import { startVitest } from 'vitest/node' /** @@ -147,6 +147,25 @@ const testCases = [ process.exitCode = 0 }, }, + { + testConfig: { + name: 'remove empty coverages directory', + include: ['option-tests/fixture.test.ts'], + coverage: { + reporter: 'text', + all: false, + include: ['src/utils.ts'], + }, + }, + after() { + if (existsSync('./coverage')) { + if (readdirSync('./coverage').length !== 0) + throw new Error('Test case expected coverage directory to be empty') + + throw new Error('Empty coverage directory was not cleaned') + } + }, + }, ] for (const provider of ['v8', 'istanbul']) {