Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Dec 5, 2024
0 parents commit c317ca5
Show file tree
Hide file tree
Showing 21 changed files with 3,814 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies
run: npm install

- name: Install browsers
run: npx playwright install chromium

- name: Run tests
run: npm test

- name: Upload test results
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
/node_modules
*.xml
__screenshots__
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Test Analytics in Vitest

Example project of using [Test Analytics from Codecov](https://docs.codecov.com/docs/test-analytics) with [Vitest Browser Mode](https://vitest.dev/guide/browser/).

## Getting started

### 1. Configure Vitest

In `vitest.config.ts`, make sure to add `juint` to the list of test `reporters` and provide the `outputFile` option to emit the report to the file system:

```js
// vitest.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
// ...other options
reporters: ['default', 'junit'],
outputFile: './test-report.junit.xml',
},
})
```

> See full [`vitest.config.ts`](./vitest.config.ts) for reference.
### 2. Install Codecov GitHub app

Click [here](https://github.com/apps/codecov/installations/select_target) to install the Codecov GitHub app in your project.

### 3. Upload test report

Create a GitHub Actions workflow that will continuously run your tests and upload the test report to Codecov. Here's an example workflow:

```yml
# .github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
# ...other steps

- name: Upload test results
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
```
> See full [`ci.yml` workflow](./.github/workflows/ci.yml) for reference.

Use the "Repository upload token" as the value for the `CODECOV_TOKEN` environment variable. You can find that value in the "Configuration > General" section of your project on Codecov:

![Codecov upload token](./codecov-upload-token.png)

Put that value as a new secret for GitHub Actions by going to your GitHub repository, "Configuration > Secrets and variables > Actions" and click the "New repository secret" button.

## Resources

- [**Test Analytics documentation**](https://docs.codecov.com/docs/test-analytics)
- [Find failing and flaky tests with Codecov Test Analytics](https://about.codecov.io/blog/find-failing-and-flaky-tests-with-codecov-test-analytics/)
- [Be S.M.A.R.T. About Flaky Tests](https://www.epicweb.dev/be-smart-about-flaky-tests)
Binary file added codecov-upload-token.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test Analytics + Vitest</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit c317ca5

Please sign in to comment.