mocha-qase-reporter
v1.3.0
Published
Mocha Cypress Reporter
Readme
Qase TestOps Mocha Reporter
Qase Mocha Reporter enables seamless integration between your Mocha tests and Qase TestOps, providing automatic test result reporting, test case management, and comprehensive test analytics.
Features
- Link automated tests to Qase test cases by ID
- Auto-create test cases from your test code
- Report test results with rich metadata (fields, attachments, steps)
- Support for parameterized tests
- Multi-project reporting support
- Flexible configuration (file, environment variables, Mocha config)
- Parallel execution support
- Extra reporters support (spec, json, etc.)
- Network Profiler for automatic HTTP request capture
Installation
npm install --save-dev mocha-qase-reporterQuick Start
1. Create qase.config.json in your project root:
{
"mode": "testops",
"testops": {
"project": "YOUR_PROJECT_CODE",
"api": {
"token": "YOUR_API_TOKEN"
}
}
}2. Configure Mocha to use the reporter in .mocharc.js:
module.exports = {
reporter: 'mocha-qase-reporter',
// ... other mocha options
};3. Add Qase ID to your test:
const { qase } = require('mocha-qase-reporter/mocha');
describe('Authentication', function() {
it(qase(1, 'User can login with valid credentials'), function() {
expect(login('[email protected]', 'password123')).to.equal(true);
});
});4. Run your tests:
QASE_MODE=testops npx mochaConfiguration
The reporter is configured via (in order of priority):
- Environment variables (
QASE_*, highest priority) - Config file (
qase.config.json)
Minimal Configuration
| Option | Environment Variable | Description |
|--------|---------------------|-------------|
| mode | QASE_MODE | Set to testops to enable reporting |
| testops.project | QASE_TESTOPS_PROJECT | Your Qase project code |
| testops.api.token | QASE_TESTOPS_API_TOKEN | Your Qase API token |
Example .mocharc.js
module.exports = {
reporter: 'mocha-qase-reporter',
require: ['@babel/register'],
spec: 'tests/**/*.spec.js',
timeout: 5000,
};Example qase.config.json
{
"mode": "testops",
"fallback": "report",
"debug": false,
"testops": {
"project": "YOUR_PROJECT_CODE",
"api": {
"token": "YOUR_API_TOKEN"
},
"run": {
"title": "Mocha Automated Run",
"complete": true
},
"batch": {
"size": 100
}
},
"report": {
"driver": "local",
"connection": {
"local": {
"path": "./build/qase-report",
"format": "json"
}
}
}
}Full configuration reference: See qase-javascript-commons for all available options including logging, status mapping, execution plans, and more.
Usage
Link Tests with Test Cases
Associate your tests with Qase test cases using test case IDs:
Single ID:
const { qase } = require('mocha-qase-reporter/mocha');
describe('User Management', function() {
it(qase(1, 'Create new user'), function() {
const user = createUser('[email protected]');
expect(user.email).to.equal('[email protected]');
});
});Multiple IDs:
describe('Login Tests', function() {
it(qase([1, 2, 3], 'Login works across different browsers'), function() {
const result = login('[email protected]', 'password');
expect(result.success).to.be.true;
});
});Add Metadata
Enhance your tests with additional information:
it('User registration', function() {
qase.title('User can register with valid email and password');
qase.fields({
severity: 'critical',
priority: 'high',
layer: 'api',
description: 'Tests user registration flow with validation',
});
qase.suite('Authentication / Registration');
const user = register('[email protected]', 'SecurePass123');
expect(user.id).to.exist;
});Ignore Tests
Exclude specific tests from Qase reporting (test still runs, but results are not sent):
it('Test under development', function() {
qase.ignore();
expect(true).to.be.true;
});Test Result Statuses
| Mocha Result | Qase Status | |--------------|-------------| | Passed | Passed | | Failed | Failed | | Pending | Skipped | | Skipped | Skipped |
For more usage examples, see the Usage Guide.
Running Tests
Run Mocha tests with Qase reporting:
# Run all tests
QASE_MODE=testops npx mocha
# Run with specific spec pattern
QASE_MODE=testops npx mocha "tests/**/*.spec.js"
# Run with grep filter
QASE_MODE=testops npx mocha --grep "authentication"
# Run with .mocharc.js configuration
QASE_MODE=testops npx mocha
# Run in parallel
QASE_MODE=testops npx mocha --parallel
# Run with extra reporters
QASE_MODE=testops npx mocha --reporter mocha-qase-reporter --reporter-options extraReporters=specParallel Execution
The reporter supports parallel execution of tests. First, create a new run in Qase.io using the Qase CLI:
# Create a new test run
qasectl testops run create --project DEMO --token token --title 'Mocha test run'
# Save the run ID to the environment variable
export QASE_TESTOPS_RUN_ID=$(< qase.env grep QASE_TESTOPS_RUN_ID | cut -d'=' -f2)
# Run tests in parallel
QASE_MODE=testops npx mocha --parallel
# Complete the run after tests finish
qasectl testops run complete --project DEMO --token token --id $(echo $QASE_TESTOPS_RUN_ID)Extra Reporters
The reporter supports additional reporters alongside the main Qase reporter. This allows you to use multiple output formats (e.g., console output and JSON reports) without the hanging issues that can occur with mocha-multi-reporters in parallel mode.
# Single extra reporter
QASE_MODE=testops npx mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec
# Multiple extra reporters
QASE_MODE=testops npx mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec,json
# With parallel execution
QASE_MODE=testops npx mocha --reporter mocha-qase-reporter --reporter-options extraReporters=spec --parallelFor detailed configuration options and examples, see the Extra Reporters section in the usage guide.
Network Profiler
The Network Profiler automatically captures outgoing HTTP requests made during test execution and reports them as REQUEST-type steps in Qase TestOps.
Enable in qase.config.json:
{
"profilers": ["network"],
"networkProfiler": {
"skip_domains": ["analytics.example.com"],
"track_on_fail": true
}
}| Option | Description | Default |
|--------|-------------|---------|
| profilers | Array of profilers to enable. Use ["network"] for HTTP capture | [] |
| networkProfiler.skip_domains | Domains to exclude from profiling | [] |
| networkProfiler.track_on_fail | Capture response body for failed requests (status >= 400) | true |
Requests to
qase.ioare always excluded automatically.
Requirements
- Node.js >= 14
- Mocha >= 8.0.0
Documentation
| Guide | Description | |-------|-------------| | Usage Guide | Complete usage reference with all methods and options | | Attachments | Adding screenshots, logs, and files to test results | | Steps | Defining test steps for detailed reporting | | Multi-Project Support | Reporting to multiple Qase projects | | Upgrade Guide | Migration guide for breaking changes |
Examples
See the examples directory for complete working examples:
License
Apache License 2.0. See LICENSE for details.
