Skip to content

Commit

Permalink
feat: Make summary and vite config path configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
davelosert committed Jun 18, 2022
1 parent 0b6bfa1 commit 76deada
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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';
Expand Down Expand Up @@ -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:

Expand All @@ -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
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
File renamed without changes.

0 comments on commit 76deada

Please sign in to comment.