Skip to content

Commit

Permalink
Merge pull request #249 from crazy-max/test-check-coverage
Browse files Browse the repository at this point in the history
test: use testResultsProcessor to check if all tests are skipped
  • Loading branch information
crazy-max authored Feb 5, 2024
2 parents 3f7d7f7 + 666b19e commit 2267dad
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
30 changes: 30 additions & 0 deletions __tests__/testResultsProcessor.ts
Original file line number Diff line number Diff line change
@@ -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;
};
1 change: 1 addition & 0 deletions jest.config.itg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ module.exports = {
},
collectCoverageFrom: ['src/**/{!(index.ts),}.ts'],
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
testResultsProcessor: './__tests__/testResultsProcessor.ts',
verbose: true
};

0 comments on commit 2267dad

Please sign in to comment.