Mocha Integration
Run your Mocha tests as usual and have results automatically reported to ProvaLab.io. Works with any Mocha project -- Node.js APIs, libraries, or backend services.
Install
npm install tms-node-sdk
Requirements: Node.js >= 18.0.0, Mocha >= 9.0.0
Configure
1. Set environment variables
export TMS_API_KEY=your-api-key
export TMS_API_URL=https://tms.yourcompany.com
export TMS_ORGANIZATION_ID=1
export TMS_PROJECT_ID=12
2. Set the ProvaLab.io reporter
Option A: In .mocharc.yml (recommended)
.mocharc.yml
reporter: tms-node-sdk/mocha/reporter
Option B: Via command line
mocha --reporter tms-node-sdk/mocha/reporter
Option C: Use alongside another reporter
mocha --reporter spec --reporter tms-node-sdk/mocha/reporter
Keep your console output
If you want to see both the normal spec output and ProvaLab.io reporting, use the multi-reporter approach shown in Option C. The ProvaLab.io reporter prints its own summary alongside your usual reporter.
Run
npx mocha
You'll see ProvaLab.io output alongside Mocha's normal output:
========================================
ProvaLab.io Mocha Integration
========================================
Test Run ID: 850
Project ID: 12
Organization ID: 1
========================================
[PASS] User API > should create a new user (0.45s)
[PASS] User API > should get user by ID (0.12s)
[FAIL] User API > should handle duplicate email (0.08s)
[SKIP] User API > should support bulk import
========================================
ProvaLab.io Test Run Summary
========================================
Test Run ID: 850
Total: 4
Passed: 2
Failed: 1
Skipped: 1
Status: FAILED
========================================
View Results in ProvaLab.io
- Open ProvaLab.io and go to your project
- Click Test Runs in the sidebar
- Find the run named "Mocha: 2026-02-20 14:30:00" (or your custom name)
- Click into it to see individual test results with error details and stack traces
Link Tests to ProvaLab.io Test Cases
Option 1: Include the ID in the test title
describe('User API', () => {
it('[TMS-401] should create a new user', async () => {
const user = await createUser({ name: 'Alice', email: '[email protected]' });
expect(user.id).to.exist;
});
it('[TMS-402] should get user by ID', async () => {
const user = await getUser(1);
expect(user.name).to.equal('Alice');
});
});
Option 2: Use a mapping file
test-case-mapping.json
{
"User API should create a new user": { "id": 401, "priority": "high" },
"User API should get user by ID": { "id": 402, "priority": "medium" }
}
export TMS_MAPPING_FILE=test-case-mapping.json
Mocha test name format
Mocha uses fullTitle() which concatenates all describe and it blocks with spaces. So describe('User API') + it('should create') becomes "User API should create".
Advanced Configuration
Custom test run name
export TMS_TEST_RUN_NAME="API Integration Tests"
Environment tagging
export TMS_ENVIRONMENT=staging
Timeout and retry
export TMS_REQUEST_TIMEOUT_MS=30000
export TMS_MAX_RETRIES=3
Disable ProvaLab.io for local development
export TMS_DISABLED=true
npx mocha
Use with TypeScript
.mocharc.yml
require:
- ts-node/register
reporter: tms-node-sdk/mocha/reporter
extension:
- ts
Verify It Works
- Set your environment variables
- Create a simple test:
test/tms-verify.test.js
const assert = require('assert');
describe('TMS Integration', () => {
it('[TMS-1] verify TMS integration', () => {
assert.strictEqual(1 + 1, 2);
});
});
- Run it:
npx mocha test/tms-verify.test.js --reporter tms-node-sdk/mocha/reporter
- Check the console output for the ProvaLab.io banner with a Test Run ID
- Open ProvaLab.io and confirm the test run appears under your project
Common issues
- "Not configured" message: Make sure
TMS_API_KEY,TMS_ORGANIZATION_ID, andTMS_PROJECT_IDare all set - Reporter not found: Check that
tms-node-sdkis installed and the path istms-node-sdk/mocha/reporter - Pending tests showing as skipped: This is expected -- Mocha
pendingtests (no callback) are reported asSKIPPEDin ProvaLab.io