omni-mocha-reporter
v1.0.11
Published
Mocha reporter that publishes test results to Omni Dashboard
Downloads
946
Maintainers
Readme
Omni Mocha Reporter
A reporter that sends test results to Omni Dashboard via HTTP APIs. Supports both Mocha and WebdriverIO frameworks with automatic detection.
Features
- ✅ Dual Framework Support: Works with both Mocha and WebdriverIO
- ✅ Automatic Detection: Automatically selects the correct reporter based on context
- ✅ TypeScript Support: Fully typed with TypeScript definitions
- ✅ Zero Configuration: Works out of the box with environment variables
Installation
npm install omni-mocha-reporterPeer Dependencies
For WebdriverIO projects, you also need:
npm install @wdio/reporterUsage
For WebdriverIO Projects
The reporter automatically detects WebdriverIO context and uses the appropriate reporter. Simply add it to your wdio.conf.js:
exports.config = {
// ... other config
reporters: [
'spec',
['omni-mocha-reporter', {
// Optional: any WebdriverIO reporter options
}]
],
// ... other config
};That's it! The package will automatically:
- Detect that you're using WebdriverIO
- Use the
OmniWDIOReporterclass - Handle all WebdriverIO events (
onRunnerStart,onTestPass,onTestFail, etc.)
For Pure Mocha Projects
When running Mocha directly, the reporter automatically uses the Mocha implementation:
# Using environment variables
OMNI_DASHBOARD_PROJECT_ID=your_project_id \
OMNI_DASHBOARD_API_KEY=your_api_key \
OMNI_DASHBOARD_ENVIRONMENT=staging \
OMNI_DASHBOARD_BASE_URL=https://omni.testvagrant.ai/api/v1 \
npx mocha --reporter omni-mocha-reporter "test/**/*.spec.js"Or in your mocha.opts or package.json:
{
"scripts": {
"test": "mocha --reporter omni-mocha-reporter"
}
}Explicit Usage (Advanced)
If you need to explicitly use a specific reporter:
const Reporter = require('omni-mocha-reporter');
// Use Mocha reporter explicitly
const mochaReporter = new Reporter.Mocha(runner, options);
// Use WebdriverIO reporter explicitly (if @wdio/reporter is available)
const wdioReporter = new Reporter.WebdriverIO(options);Configuration
Environment Variables
The following environment variables are required:
OMNI_DASHBOARD_PROJECT_ID- Your Omni Dashboard project IDOMNI_DASHBOARD_API_KEY- Your Omni Dashboard API keyOMNI_DASHBOARD_ENVIRONMENT- Environment (e.g., staging, production)OMNI_DASHBOARD_BASE_URL- Base URL for Omni Dashboard API (defaults tohttps://omni.testvagrant.ai/api/v1)
How It Works
The package automatically detects which framework you're using:
- WebdriverIO Detection: If the first parameter passed to the reporter constructor has WebdriverIO-specific properties (
outputDir,logFile,writeStream), it usesOmniWDIOReporter - Mocha Detection: Otherwise, it uses
OmniMochaReporterwhich works with Mocha'sRunnerobject
Both reporters share the same base functionality (OmniReporterBase) for:
- Creating builds
- Uploading test cases
- Completing builds
- Queue management
Development
Building the Reporter
cd omni-mocha-reporter
npm run buildAdding New Tests
Add your test files to the omni-mocha-tests/demo/ directory with the .spec.ts extension.
API Integration
The reporter integrates with Omni Dashboard through the following API endpoints:
- Create Build -
POST /projects/{projectId}/builds - Upload Test Case -
POST /projects/{projectId}/test-cases - Complete Build -
PATCH /projects/{projectId}/builds?build_id={buildId}
License
TBD
