vitest-qase-reporter
v1.0.2
Published
Qase TMS Vitest Reporter
Downloads
887
Readme
Qase TestOps Vitest reporter
Qase Vitest reporter sends test results and metadata to Qase.io. It can work in different test automation scenarios:
- Create new test cases in Qase from existing autotests.
- Report Vitest test results to existing test cases in Qase.
Testing frameworks that use Vitest as a test runner can also be used with Vitest reporter.
To install the latest version, run:
npm install --save-dev qase-vitestContents
Getting started
To report your tests results to Qase, install qase-vitest,
and add a reporter config in the vitest.config.ts file.
A minimal configuration needs just two things:
- Qase project code, for example, in https://app.qase.io/project/DEMO the code is
DEMO. - Qase API token, created on the Apps page.
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
reporters: [
'default',
[
'vitest-qase-reporter',
{
mode: 'testops',
testops: {
api: {
token: 'api_token'
},
project: 'project_code',
},
},
],
],
},
});Now, run the Vitest tests as usual. Test results will be reported to a new test run in Qase.
$ npx vitest run
Determining test suites to run...
...
qase: Project DEMO exists
qase: Using run 42 to publish test results
...
Ran all test suites.Using Reporter
The Vitest reporter has the ability to auto-generate test cases and suites from your test data.
But if necessary, you can independently register the ID of already existing test cases from TMS before the executing tests. For example:
Metadata
qase.title- set the title of the test caseqase.fields- set the fields of the test caseqase.suite- set the suite of the test caseqase.comment- set the comment of the test caseqase.parameters- set the parameters of the test caseqase.groupParameters- set the group parameters of the test caseqase.ignore- ignore the test case in Qase. The test will be executed, but the results will not be sent to Qase.qase.step- create a step in the test caseqase.attach- attach a file to the test case
import { describe, it, test, expect } from 'vitest';
import { qase, withQase } from 'vitest-qase-reporter/vitest';
describe('My First Test', () => {
test(qase([1, 2], 'Several ids'), () => {
expect(true).toBe(true);
});
test(qase(3, 'Correct test'), () => {
expect(true).toBe(true);
});
test.skip(qase('4', 'Skipped test'), () => {
expect(true).toBe(true);
});
test(qase(['5', '6'], 'Failed test'), () => {
expect(true).toBe(false);
});
});Advanced Usage with Annotations
import { describe, it, expect } from 'vitest';
import { qase, withQase } from 'vitest-qase-reporter/vitest';
describe('Qase Annotations Example', () => {
it(qase(20, 'Basic test with qase ID'), () => {
expect(1 + 1).toBe(2);
});
it('Test with qase annotations', withQase(async ({ qase, annotate }) => {
// Set test title
await qase.title('Advanced Test with Annotations');
// Add comment
await qase.comment('This test demonstrates qase annotations functionality');
// Set suite
await qase.suite('Vitest Integration Suite');
// Set fields
await qase.fields({
description: 'Test description for Qase',
severity: 'critical',
priority: 'high',
layer: 'e2e'
});
// Set parameters
await qase.parameters({
environment: 'staging',
browser: 'chrome',
version: '1.0.0'
});
// Add steps
await qase.step('Initialize test data', async () => {
expect(true).toBe(true);
});
await qase.step('Execute main test logic', async () => {
expect(2 + 2).toBe(4);
});
// Add attachment with content
await qase.attach({
name: 'test-data.json',
content: JSON.stringify({ test: 'data' }),
type: 'application/json'
});
// Use regular annotate for custom annotations
await annotate('Custom annotation message', 'info');
// Final assertion
expect(Math.max(1, 2, 3)).toBe(3);
}));
});To run tests and create a test run, execute the command (for example from folder examples):
QASE_MODE=testops npx vitest runor
npm testA test run will be performed and available at:
https://app.qase.io/run/QASE_PROJECT_CODEConfiguration
Reporter options (* - required):
mode-testops/offEnables reporter, default -offdebug- Enables debug logging, default -falseenvironment- To execute with the sending of the environment informationcaptureLogs- Capture console logs, default -falseuploadAttachments- Upload attachments to Qase, default -false- *
testops.api.token- Token for API access, you can generate it here. - *
testops.project- Your project's code testops.api.baseUrl- Qase API base URL (optional)testops.run.id- Qase test run ID, used when the test run was created earlier using CLI or API call.testops.run.title- Set custom Run name, when new run is createdtestops.run.description- Set custom Run description, when new run is createdtestops.run.complete- Whether the run should be completed
Example vitest.config.ts config:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
reporters: [
'default',
[
'vitest-qase-reporter',
{
mode: 'testops',
testops: {
api: {
token: 'api_key'
},
project: 'project_code',
run: {
complete: true,
},
uploadAttachments: true,
},
debug: true,
captureLogs: true,
},
],
],
},
});You can check example configuration with multiple reporters in example project.
Supported ENV variables:
QASE_MODE- Same asmodeQASE_DEBUG- Same asdebugQASE_ENVIRONMENT- Same asenvironmentQASE_TESTOPS_API_TOKEN- Same astestops.api.tokenQASE_TESTOPS_PROJECT- Same astestops.projectQASE_TESTOPS_RUN_ID- Pass Run ID from ENV and override reporter optiontestops.run.idQASE_TESTOPS_RUN_TITLE- Same astestops.run.titleQASE_TESTOPS_RUN_DESCRIPTION- Same astestops.run.description
Documentation
For detailed documentation and advanced usage, see USAGE.md.
Requirements
We maintain the reporter on LTS versions of Node. You can find the current versions by following the link
vitest >= 3.0.0
