Skip to content

Commit

Permalink
[chore]: testing codecov coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tarun-khanna committed Nov 7, 2023
1 parent 533a9a9 commit 2c13ef4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .github/workflows/unit-test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CodeCov Code Coverage PR Analysis

on:
pull_request:
branches:
- master

jobs:
coverage:
name: Sonar analysis on coverage
runs-on: ubuntu-latest
if: |
!(github.head_ref == 'changeset-release/master' && github.actor == 'rzpcibot') &&
!contains(github.event.head_commit.message, '[skip ci]')
steps:
- name: Checkout Codebase
uses: actions/checkout@v3
with:
token: ${{ secrets.CI_BOT_TOKEN }}
- name: Setup Node v20
uses: actions/setup-node@v3
with:
node-version: 20.3.1
- name: Setup Cache & Install Dependencies
uses: bahmutov/[email protected]
with:
install-command: yarn --frozen-lockfile
- name: Run Tests
run: yarn test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
verbose: true
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: Unit Test Results
path: src/coverage/**/*.xml

publish-test-results:
name: 'Publish Unit Tests Results'
needs: coverage
runs-on: ubuntu-latest
# Only run if prereq jobs completed - successfully or not
if: success() || failure()
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
path: artifacts

- name: Publish Unit Test Results
uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1.6
continue-on-error: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: artifacts/**/*.xml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
lib
.DS_Store
.DS_Store
coverage
11 changes: 11 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
const config = {
collectCoverage: true,
preset: 'ts-jest',
testEnvironment: 'jsdom',
collectCoverageFrom: ['**/*.{ts,js}', '!coverage/**/*.{ts,tsx,js,jsx}'],
coverageThreshold: {
'./src/': {
statements: 0,
branches: 0,
functions: 0,
lines: 0,
},
},
rootDir: 'src',
};

export default config;
5 changes: 5 additions & 0 deletions src/modules/currency/formatCurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ export default function (currency: keyof typeof CURRENCIES, amount: number) {
amount,
);
}

export const test = (inp) => {
if (inp === 1) return 'a';
return 'b';
};
8 changes: 8 additions & 0 deletions src/modules/currency/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { test } from './formatCurrency';

describe('test function', () => {
it('test function test', () => {
const res = test(1);
expect(res).toBe('a');
});
});

0 comments on commit 2c13ef4

Please sign in to comment.