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

Adding vitest coverage using github workflow #15

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
},
});
Loading