Merge pull request #249 from crazy-max/test-check-coverage

test: use testResultsProcessor to check if all tests are skipped
This commit is contained in:
CrazyMax 2024-02-05 10:30:16 +01:00 committed by GitHub
commit 2267dad53e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 54 additions and 2 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
uses: codecov/codecov-action@v4
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
uses: codecov/codecov-action@v4
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
};