|
| 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 | +}; |
0 commit comments