Registry / testing / mocha-tags-ultra

mocha-tags-ultra

JSON →
library1.0.3jsnpmunverified

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-ultra
INSTALL
IMPORT
SIG · MOCHA-TAGS-ULTRA
M
mocha-tags-ultra
testingjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tags
const tags = require('mocha-tags-ultra');
Primarily used as a CommonJS module. ESM import might work with tooling but `require` is the documented approach.
tags.Filter
const tags = require('mocha-tags-ultra'); const myFilter = new tags.Filter('is:unit');
Used for programmatic manipulation of the test filter. Access it via the main `tags` export.
tags().describe
const tags = require('mocha-tags-ultra'); tags('unit').describe('My Unit Test Suite', () => { /* ... */ });
describe('My Test Suite', () => { /* ... */ });
This is the primary way to apply tags to `describe` blocks. It wraps Mocha's original `describe`.
tags().it
const tags = require('mocha-tags-ultra'); tags('fast').it('should run quickly', () => { /* ... */ });
it('should run quickly', () => { /* ... */ });
This is the primary way to apply tags to `it` blocks. It wraps Mocha's original `it`.

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.

const tags = require('mocha-tags-ultra'); const assert = require('assert'); // Simulate an external library like moment for programmatic filtering const moment = () => ({ hours: () => new Date().getHours() }); // Programmatic filter example: Only run trading-hours tests during business hours if (moment().hours() < 8 || moment().hours() > 18) { tags.filter.remove('not:unit'); // Example of modifying existing filter tags.filter.add('not:trading-hours'); } // Log the active filter for debugging console.log('Test filter: ', tags.filter.toString()); tags('network', 'slow') .describe('Network Operations', () => { tags('integration').it('should fetch data from an API', () => { assert.ok(true, 'This test runs if network and integration tags match filters'); }); }); tags('unit', 'fast') .it('should perform a quick calculation', () => { assert.strictEqual(1 + 1, 2, 'This is a fast unit test'); }); tags('trading-hours').it( 'should execute a trade during market hours', () => { assert.ok(moment().hours() >= 8 && moment().hours() <= 18, 'This test only runs during market hours'); } ); // Example of how to run this: // mocha --require <path_to_this_file> --tags "is:unit not:slow" // or mocha --require <path_to_this_file> --tags "is:network+integration"
mocha-tags-ultra --version
Debug
Known issues
gotchaTags must be single words without spaces due to the parsing mechanism. Multi-word tags will not work as expected.
fix
Ensure all tags are single, contiguous words (e.g., `api-integration` instead of `api integration`).
affects: >=1.0.0
gotchaWhen tests are skipped by `mocha-tags-ultra` filters, they appear as 'pending' in the Mocha test output, not explicitly 'skipped'.
fix
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.
affects: >=1.0.0
gotchaUsing `--tags` with `mocha.only` or `mocha.skip` (e.g., `describe.only`, `it.skip`) will prioritize Mocha's native filtering. `tags().describe.only` and `tags().it.skip` are provided for explicit control within `mocha-tags-ultra` context.
fix
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`).
affects: >=1.0.0
Errors
Common errors & fixes
Some tests are showing as 'pending' when I expect them to run.
The current `--tags` filter or a programmatic filter is causing tests to be skipped. `mocha-tags-ultra` marks skipped tests as 'pending' in Mocha's output.
fix
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.
My tags with spaces (e.g., 'slow integration') are not being recognized by the filter.
The `--tags` filter parser requires tags to be single words, without spaces.
fix
Rename your tags to be single words, often using hyphens or underscores (e.g., `slow-integration`).
I'm trying to import `tags` using `import { tags } from 'mocha-tags-ultra'` and it's failing.
The `mocha-tags-ultra` package is primarily distributed as a CommonJS module.
fix
Use CommonJS `require` syntax: `const tags = require('mocha-tags-ultra');`.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
mocharequiredPeer dependency; this package extends Mocha's test definition capabilities.
Agent activity
2 hits · last 30 days
node
2
Resources
mocha-tags-ultra — npm install mocha-tags-ultra · libregistry