Vitest
Submit and collect your Vitest results in Testiny to track automated test runs. By integrating Vitest with Testiny, you can gain valuable insights into your testing process. Track automation results over time, identify frequently failing tests, and detect patterns in test failures to fix CI failures and find flaky tests.
Generate Vitest JSON Reports
Vitest provides built-in support for generating JSON test reports, making it easy to integrate with CI/CD pipelines and test reporting tools. To generate a JSON report, simply run Vitest with the --reporter=json option and specify an output file path with --outputFile:
npx vitest run --reporter=json --outputFile=output/results.json
When you execute this command, Vitest will run all available tests and generate a structured JSON report in the specified file. You can also specify another output directory.
Import Results to Testiny
Make sure you've generated an API key and use the Testiny CLI to import the results to Testiny:
- Node.js/npm
- Linux
- Windows
- macOS
export TESTINY_API_KEY=****
npx @testiny/cli automation --project ID_OR_KEY --source "frontend" --vitest output/results.json export TESTINY_API_KEY=****
./testiny-importer-linux automation --project ID_OR_KEY --source "frontend" --vitest output/results.json set TESTINY_API_KEY=****
testiny-importer-win.exe automation --project ID_OR_KEY --source "frontend" --vitest output/results.json export TESTINY_API_KEY=****
./testiny-importer-macos automation --project ID_OR_KEY --source "frontend" --vitest output/results.json In the above example, the environment variable TESTINY_API_KEY is set to authenticate the request.
The --project flag specifies the target Testiny project using its ID or key and the --source flag categorizes the test results (e.g., frontend, backend, integration tests, ...).
The --vitest flag specifies the format of the specified test result file(s).
Once executed, the Testiny CLI will automatically create a new automated test run in Testiny and import all results from the specified report(s).
Vitest Test Annotations
With Test Annotations you can add additional information to your automated tests.
Test Keys
The testid or testkey are optional properties that can be used to uniquely identify a test across automation runs. If not specified, a combination of title and folder path will be used to identify a test.
Set test keys with annotations:
test('sample test', async ({ annotate }) => {
await annotate('my-testid-1', 'testkey')
//...
})
Custom Result Fields
Custom fields are supported via annotations and can be included as fields via the CLI and reporter:
// annotate your tests with custom fields:
test('sample test', async ({ annotate }) => {
await annotate('smoke', 'type')
await annotate('high', 'priority')
//...
})
When importing your test results with the Testiny CLI, specify which annotations you want to import with the option --custom-result-fields (or for the reporter, set property customResultFields):
--custom-result-fields=type,priority
More resources
Here are some further resources to help you get started with integrating Vitest with Testiny, including CI/CD integration examples, a full automation guide, and the Testiny CLI.