diff --git a/README.md b/README.md index 97d670b..9954368 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # vitest-coverage-report-action -A GitHub Action to report [vitest](https://vitest.dev/) coverage results as a step-summary and PR comment. +A GitHub Action to report [vitest](https://vitest.dev/) coverage results as a GitHub step-summary and Pull-Request comment. ![Coverage Report as Step Summary](./docs/coverage-report.png) @@ -12,7 +12,7 @@ This action requires you to use `vitest` to create a `json-summary` report as `c npx vitest run --coverage.reporter json-summary ``` -Or by adding the configuration to you `vitest.config.js`-File: +Or by adding the configuration to you `vite.config.js`-File: ```js import { defineConfig } from 'vite'; @@ -54,7 +54,7 @@ jobs: ### Coverage Thresholds -This action will read the coverage thresholds defined in the `coverage`-property of the `vitest.config.js`-File and mark the status of the generated report accordingly. +This action will read the coverage thresholds defined in the `coverage`-property of the `vite.config.js`-file and mark the status of the generated report accordingly. E.g. with a config like this: @@ -79,16 +79,17 @@ the report would look like this: ## Current Status -This is a work in progress project. Currently, it will only take an already created `json-summary`-reporter, convert it to markdown and export that to: +This is a work in progress project. Currently, it will only take an already created `json-summary`-report, convert it to markdown and export it to: 1. a comment within an associated pull-request (if there is one) -2. the [GitHub Step Summary](https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables) +2. the [GitHub Step Summary](https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables) of the current action ### Future Plans +- [x] Make summary file configurable - [ ] Also report detailed file-coverage (coverage per file and unconvered lines) based on the `json`-Reporter -- [ ] Make summary file configurable - [ ] Invoke 'vitest' directly from the action - [ ] Also provide test results (failed tests etc.) in the generated markdown reports - [ ] Add option to let the action fail if coverage thresholds are not met - [ ] Also report test results themselves +- [ ] Beatufiy the report with better markdown diff --git a/action.yml b/action.yml index 334b9a4..5b064d5 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,14 @@ inputs: required: false description: 'A github access token. Uses secrets.GITHUB_TOKEN by default.' default: ${{ github.token }} + vite-config-path: + required: false + description: 'The path to the vite config file. Uses "vite.config.js" by default.' + default: vite.config.js + json-summary-path: + required: false + description: 'The path to the json summary file. Uses "coverage/coverage-summary.json" by default.' + default: coverage/coverage-summary.json runs: using: 'node16' main: 'dist/index.js' diff --git a/src/index.ts b/src/index.ts index 411586a..7327867 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,12 +5,12 @@ import { writeSummaryToPR } from './writeSummaryToPR.js'; import * as core from '@actions/core'; import { parseThresholds } from './parseThresholds.js'; -const DEFAULT_SUMMARY_PATH = path.join('coverage', 'coverage-summary.json'); -const DEFAULT_VITEST_CONFIG_PATH = path.join('vitest.config.js'); - const run = async () => { - const jsonSummary = await parseJsonSummary(DEFAULT_SUMMARY_PATH); - const thresholds = await parseThresholds(DEFAULT_VITEST_CONFIG_PATH); + // get action input for json-summary-path + const jsonSummaryPath = path.resolve(core.getInput('json-summary-path')); + const viteConfigPath = path.resolve(core.getInput('vite-config-path')); + const jsonSummary = await parseJsonSummary(jsonSummaryPath); + const thresholds = await parseThresholds(viteConfigPath); const tableData = generateSummaryTableData(jsonSummary, thresholds); diff --git a/vitest.config.js b/vite.config.js similarity index 100% rename from vitest.config.js rename to vite.config.js