Skip to content

Commit

Permalink
Merge pull request #15 from gokulk16/r-12
Browse files Browse the repository at this point in the history
Adding vitest coverage using github workflow
  • Loading branch information
gokulk16 authored Jun 6, 2024
2 parents 648c40d + 947581e commit 942c7f6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
62 changes: 46 additions & 16 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
# For more information see: https://github.com/marketplace/actions/vitest-coverage-report

name: Node.js CI
name: Node.js Test Coverage Report

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]

jobs:
build:

test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
branch:
- ${{ github.head_ref }}
- "main"
permissions:
# Required to checkout the code
contents: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "npm"
- name: "Install Deps"
run: npm ci
- name: "Build"
run: npm run build
- name: "Test"
run: npm run coverage-summary
- name: "Upload Coverage"
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.branch }}
path: coverage

report-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm test
- name: "Download Coverage Artifacts"
uses: actions/download-artifact@v4
with:
name: coverage-${{ github.head_ref }}
path: coverage
- uses: actions/download-artifact@v4
with:
name: coverage-main
path: coverage-main
- name: "Vitest Coverage Differences from main"
uses: davelosert/vitest-coverage-report-action@v2
with:
json-summary-compare-path: coverage-main/coverage-summary.json
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build": "node esbuild.js",
"test": "vitest",
"coverage": "vitest run --coverage",
"coverage-summary": "vitest run --coverage.enabled --reporter=json --coverage.reporter=json-summary",
"watch": "npm-watch"
},
"watch": {
Expand Down
8 changes: 8 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
coverage: {
enabled: true,
reporter: [
["json-summary", { file: "coverage-summary.json" }],
"json",
"json-summary-compare-path",
"text",
],
reportOnFailure: true,
},
test: {
environment: "jsdom",
reporters: process.env.GITHUB_ACTIONS ? ["dot", "github-actions"] : ["dot"],
},
});

0 comments on commit 942c7f6

Please sign in to comment.