Skip to content

Commit

Permalink
Create an example using Vitest with Captain
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekthompson committed Aug 22, 2024
0 parents commit 0b83836
Show file tree
Hide file tree
Showing 10 changed files with 1,548 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .captain/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test-suites:
captain-examples-vitest:
command: npx vitest run --reporter=default --reporter=json --outputFile=./tmp/vitest.json
results:
path: tmp/vitest.json
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Captain Vitest Integration Example"
on:
- push

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 22.x
- uses: rwx-research/setup-captain@v1
- run: npm install
- run: captain run captain-examples-vitest
env:
RWX_ACCESS_TOKEN: ${{ secrets.RWX_ACCESS_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
tmp
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT LICENSE

Copyright (c) 2024 ReadWriteExecute, Inc. and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Getting Captain working with Vitest

To configure Vitest such that it works with Captain, we need to:

1. 🧪 Ensure vitest produces json output

`npx vitest run --reporter=default --reporter=json --outputFile=./tmp/vitest.json` will produce Captain-compatible JSON output in `tmp/vitest.json`.
To ensure GitHub logs continue to have test output, also include a stdout-friendly reporter (for example, `--reporter=default`).

```yaml
# .captain/config.yaml
test-suites:
captain-examples-vitest:
command: npx vitest run --reporter=default --reporter=json --outputFile=./tmp/vitest.json
results:
path: tmp/vitest.json
```
Additionally, you'll need to make sure `includeTaskLocation` is set to `true` in the `test` section of your Vitest config:

```ts
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
includeTaskLocation: true,
},
});
```

2. 🔐 Create an Access Token

Create an Access Token for your organization within [Captain][captain] ([more documentation here][create-access-token]).

Add the new token as an action secret to your repository. Conventionally, we call this secret `RWX_ACCESS_TOKEN`.

3. 💌 Install the Captain CLI, and then call it when running tests

See the [full documentation on test suite integration][test-suite-integration].

```yaml
- uses: rwx-research/setup-captain@v1
- run: captain run captain-examples-vitest
env:
RWX_ACCESS_TOKEN: ${{ secrets.RWX_ACCESS_TOKEN }}
```

4. 🎉 See your test results in Captain!

Take a look at the [final workflow!][workflow-with-captain]

[captain]: https://account.rwx.com/deep_link/manage/access_tokens
[create-access-token]: https://www.rwx.com/docs/access-tokens
[workflow-with-captain]: https://github.com/captain-examples/vitest/blob/main/.github/workflows/ci.yml
[test-suite-integration]: https://www.rwx.com/captain/docs/test-suite-integration
Loading

0 comments on commit 0b83836

Please sign in to comment.