Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage #733

Merged
merged 18 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Unit test & Code coverage
on: [push]
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Node 16.14.2
uses: actions/setup-node@v3
with:
node-version: 16.14.2
priojeetpriyom marked this conversation as resolved.
Show resolved Hide resolved
- name: Install dependencies
run: npm ci
- name: Run unit tests and collect coverage
run: npm run test:unit
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
17 changes: 17 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codecov:
max_report_age: 30
notify:
wait_for_ci: false
github_checks:
annotations: false
coverage:
status:
project:
default:
# basic
target: auto
threshold: 0%
base: auto
comment:
layout: 'reach, diff, flags, files'
behavior: default
40 changes: 40 additions & 0 deletions jest.unit.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
priojeetpriyom marked this conversation as resolved.
Show resolved Hide resolved
globals: {
'ts-jest': {
tsconfig: './test/tsconfig.json',
},
},
testMatch: ['<rootDir>/test/**/?(*.)+(spec|test).+(ts|tsx|js)'],
setupFilesAfterEnv: ['<rootDir>/test/_setup.js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
verbose: true,
collectCoverage: true,
coverageReporters: ['text', 'json'],
coverageDirectory: '.coverage',
/**
* restoreMocks [boolean]
*
* Default: false
*
* Automatically restore mock state between every test.
* Equivalent to calling jest.restoreAllMocks() between each test.
* This will lead to any mocks having their fake implementations removed
* and restores their initial implementation.
*/
restoreMocks: true,
resetMocks: true,

/**
* resetModules [boolean]
*
* Default: false
*
* By default, each test file gets its own independent module registry.
* Enabling resetModules goes a step further and resets the module registry before running each individual test.
* This is useful to isolate modules for every test so that local module state doesn't conflict between tests.
* This can be done programmatically using jest.resetModules().
*/
resetModules: true,
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"prebuild": "if test -d dist; then rm -r dist; fi; rm -f tsconfig.tsbuildinfo; rm -f npm-shrinkwrap.json",
"build": "tsc",
"test": "jest",
"test:unit": "jest --config=jest.unit.config.js",
priojeetpriyom marked this conversation as resolved.
Show resolved Hide resolved
"test:coverage": "jest --coverage=true --coverage-reporters=text",
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose",
"test:stress": "npx ts-node test/scripts/stress_test.ts",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["./src/**/*.ts", "./src/**/*.json"]
"include": ["./src/**/*.ts", "./src/**/*.json", "jest.unit.config.js"]
priojeetpriyom marked this conversation as resolved.
Show resolved Hide resolved
}