Skip to content

Commit b1b6c30

Browse files
committed
test: restore all-skipped coverage guard with custom reporter
Signed-off-by: CrazyMax <[email protected]>
1 parent 1b45318 commit b1b6c30

5 files changed

Lines changed: 86 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
-
4848
name: Check coverage
4949
run: |
50-
if [ -f ./coverage/clover.xml ]; then
50+
if [ -f ./coverage/clover.xml ] && [ ! -f ./coverage/allSkipped.txt ]; then
5151
echo "RUN_CODECOV=true" >> $GITHUB_ENV
5252
else
5353
echo "RUN_CODECOV=false" >> $GITHUB_ENV
@@ -217,7 +217,7 @@ jobs:
217217
-
218218
name: Check coverage
219219
run: |
220-
if [ -f ./coverage/clover.xml ]; then
220+
if [ -f ./coverage/clover.xml ] && [ ! -f ./coverage/allSkipped.txt ]; then
221221
echo "RUN_CODECOV=true" >> $GITHUB_ENV
222222
else
223223
echo "RUN_CODECOV=false" >> $GITHUB_ENV
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2026 actions-toolkit authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import type {Reporter} from 'vitest/node';
18+
19+
export declare const vitestAllSkippedReporter: () => Reporter;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2026 actions-toolkit authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import fs from 'node:fs';
18+
import path from 'node:path';
19+
20+
export const vitestAllSkippedReporter = () => {
21+
let vitest;
22+
let hasExecutedTest;
23+
let hasAnyCollectedTest;
24+
25+
const getFlagPath = () => {
26+
const reportsDirectory = vitest?.config?.coverage?.reportsDirectory ?? 'coverage';
27+
return path.join(reportsDirectory, 'allSkipped.txt');
28+
};
29+
30+
return {
31+
onInit(ctx) {
32+
vitest = ctx;
33+
hasExecutedTest = false;
34+
hasAnyCollectedTest = false;
35+
},
36+
onTestCaseReady() {
37+
hasAnyCollectedTest = true;
38+
},
39+
onTestCaseResult(testCase) {
40+
const state = testCase.result()?.state;
41+
if (state === 'passed' || state === 'failed') {
42+
hasExecutedTest = true;
43+
}
44+
},
45+
onTestRunEnd() {
46+
if (!vitest?.config?.coverage?.enabled) {
47+
return;
48+
}
49+
const allSkipped = hasAnyCollectedTest && !hasExecutedTest;
50+
const flagPath = getFlagPath();
51+
if (allSkipped) {
52+
fs.mkdirSync(path.dirname(flagPath), {recursive: true});
53+
fs.writeFileSync(flagPath, '');
54+
} else if (fs.existsSync(flagPath)) {
55+
fs.rmSync(flagPath);
56+
}
57+
}
58+
};
59+
};

vitest.config.itg.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
*/
1616

1717
import {defineConfig} from 'vitest/config';
18+
import {vitestAllSkippedReporter} from './__tests__/.setup/skipped-reporter.mjs';
1819

1920
export default defineConfig({
2021
test: {
2122
clearMocks: true,
2223
environment: 'node',
2324
include: ['**/*.test.itg.ts'],
2425
testTimeout: 1800000,
26+
reporters: ['default', vitestAllSkippedReporter()],
2527
coverage: {
2628
provider: 'v8',
2729
reporter: ['clover'],
2830
include: ['src/**/*.ts'],
29-
exclude: ['src/**/index.ts']
31+
exclude: ['src/**/index.ts', '__tests__/**', 'lib/**']
3032
}
3133
}
3234
});

vitest.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
*/
1616

1717
import {defineConfig} from 'vitest/config';
18+
import {vitestAllSkippedReporter} from './__tests__/.setup/skipped-reporter.mjs';
1819

1920
export default defineConfig({
2021
test: {
2122
clearMocks: true,
2223
environment: 'node',
2324
setupFiles: ['./__tests__/.setup/setup.unit.ts'],
2425
include: ['**/*.test.ts'],
26+
reporters: ['default', vitestAllSkippedReporter()],
2527
coverage: {
2628
provider: 'v8',
2729
reporter: ['clover'],
2830
include: ['src/**/*.ts'],
29-
exclude: ['src/**/index.ts']
31+
exclude: ['src/**/index.ts', '__tests__/**', 'lib/**']
3032
}
3133
}
3234
});

0 commit comments

Comments
 (0)