mocha-tags-ultra is a utility for the Mocha test framework that allows developers to associate tags with their test suites and individual tests. It enables runtime filtering of tests based on these tags, supporting 'is:' and 'not:' criteria, as well as logical AND ('+') for more granular control. This is particularly useful for segmenting tests (e.g., 'unit', 'integration', 'network') and running only relevant subsets during development or CI/CD pipelines. The current stable version is 1.0.3. The package integrates by wrapping Mocha's `describe` and `it` functions, providing a fluent API for tag assignment. Key differentiators include its simple CLI integration, programmatic filtering options, and clear indication of skipped tests as 'pending' in Mocha's output.
npm install mocha-tags-ultraVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up tagged `describe` and `it` blocks, including programmatic filter modification based on time, and how to debug the active filter.
Ensure all tags are single, contiguous words (e.g., `api-integration` instead of `api integration`).
Monitor your test output for 'pending' tests to identify any unexpectedly skipped tests. The `console.log('Test filter:', tags.filter)` can help debug why tests are skipped.If you intend to use `mocha-tags-ultra` filtering, use `tags().describe` and `tags().it`. For overriding tags and forcing a run, use `tags().describe.only` or `tags().it.only`. For explicit skipping, use `tags().xdescribe` or `tags().xit` (or `tags().describe.skip`, `tags().it.skip`).
Add `console.log('Test filter: ', tags.filter);` at the top of your test file to inspect the active filter. Review your `--tags` CLI arguments for correctness and ensure your programmatic filter logic is accurate.Rename your tags to be single words, often using hyphens or underscores (e.g., `slow-integration`).
Use CommonJS `require` syntax: `const tags = require('mocha-tags-ultra');`.