Skip to content

Commit

Permalink
test: Code coverage with nyc and Codecov Github Action (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
avaly committed Aug 5, 2023
1 parent e18485e commit d976c22
Show file tree
Hide file tree
Showing 7 changed files with 744 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ indent_style = tab
indent_size = 2
insert_final_newline = true

[{package.json,.travis.yml}]
[{package.json,*.yaml}]
indent_style = space
indent_size = 2
14 changes: 10 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ on:
jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node: [12, 14, 16, 18, 20]

name: Node.js ${{ matrix.node }}

steps:
- uses: actions/checkout@v3.3.0
- uses: actions/setup-node@v3.6.0
Expand All @@ -27,4 +24,13 @@ jobs:
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn test
- run: yarn codecov
- run: yarn coverage
if: matrix.node == 18
- name: Upload coverage to Codecov
if: matrix.node == 18
uses: codecov/codecov-action@v3.1.4
with:
directory: ./coverage/
fail_ci_if_error: true
name: codecov
verbose: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin/*.lock
/.nyc_output/
/coverage/
/data/
/node_modules
Expand Down
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "A simple backup tool which uploads encrypted files to S3",
"author": "Valentin Agachi",
"scripts": {
"coverage": "rm -rf coverage/ && COVERAGE=1 yarn test && istanbul report lcov",
"codecov": "yarn coverage && codecov",
"coverage": "rm -rf .nyc_output/ coverage/ && BACKUP_ENV=test nyc --reporter=text --reporter=lcov mocha test/*-test.js",
"lint": "eslint . bin/backup-to-cloud --ignore-pattern '!.eslintrc.js'",
"pretty": "prettier --write --list-different \"**/*.js\"",
"release": "standard-version",
Expand Down Expand Up @@ -41,14 +40,13 @@
},
"devDependencies": {
"chai": "^4.2.0",
"codecov": "^3.5.0",
"conventional-recommended-bump": "^6.0.0",
"eslint": "^6.2.2",
"husky": "3.0.4",
"istanbul": "^0.4.5",
"lint-staged": "9.2.5",
"md5-file": "4.0.0",
"mocha": "^6.2.0",
"nyc": "15.1.0",
"prettier": "1.18.2",
"standard-version": "^7.0.0",
"validate-commit-msg": "^2.14.0"
Expand Down
16 changes: 2 additions & 14 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,9 @@ module.exports = {

run: (args, binFile, allowFailure = false) => {
const bin = BIN_FILES[binFile || 'backup'];
const cmd = process.env.COVERAGE ? './node_modules/.bin/istanbul' : bin;
const filteredArgs = args.filter(arg => !!arg);
// prettier-ignore
const execArgs = process.env.COVERAGE
? [
'cover',
'--report', 'none',
'--print', 'none',
'--include-pid',
bin,
'--'
].concat(filteredArgs)
: filteredArgs;

const promise = utils.execPromise(cmd, execArgs);

const promise = utils.execPromise(bin, filteredArgs);

if (allowFailure) {
return promise.catch(err => err);
Expand Down

0 comments on commit d976c22

Please sign in to comment.