test: use testResultsProcessor to check if all tests are skipped

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2024-02-05 10:07:54 +01:00
parent 3f7d7f75b5
commit a5975adf41
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
4 changed files with 52 additions and 0 deletions

View File

@ -30,9 +30,19 @@ jobs:
targets: test-coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Check coverage
run: |
if [ -f ./coverage/clover.xml ] && [ ! -f ./coverage/allSkipped.txt ]; then
echo "RUN_CODECOV=true" >> $GITHUB_ENV
else
echo "RUN_CODECOV=false" >> $GITHUB_ENV
fi
shell: bash
-
name: Upload coverage
uses: codecov/codecov-action@v3
if: env.RUN_CODECOV == 'true'
with:
file: ./coverage/clover.xml
flags: unit
@ -100,9 +110,19 @@ jobs:
yarn test:itg-coverage --runTestsByPath __tests__/${{ matrix.test }} --coverageDirectory=./coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Check coverage
run: |
if [ -f ./coverage/clover.xml ] && [ ! -f ./coverage/allSkipped.txt ]; then
echo "RUN_CODECOV=true" >> $GITHUB_ENV
else
echo "RUN_CODECOV=false" >> $GITHUB_ENV
fi
shell: bash
-
name: Upload coverage
uses: codecov/codecov-action@v3
if: env.RUN_CODECOV == 'true'
with:
file: ./coverage/clover.xml
flags: itg

View File

@ -0,0 +1,30 @@
/**
* Copyright 2024 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
module.exports = results => {
const allSkipped = results.testResults.every(result => {
return result.skipped;
});
if (allSkipped) {
console.log('All tests were skipped!');
// create an empty file to signal that all tests were skipped for CI
fs.closeSync(fs.openSync('./coverage/allSkipped.txt', 'w'));
}
return results;
};

View File

@ -27,5 +27,6 @@ module.exports = {
moduleNameMapper: {
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
},
testResultsProcessor: './__tests__/testResultsProcessor.ts',
verbose: false
};

View File

@ -43,5 +43,6 @@ module.exports = {
},
collectCoverageFrom: ['src/**/{!(index.ts),}.ts'],
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
testResultsProcessor: './__tests__/testResultsProcessor.ts',
verbose: true
};