The powerful, easy-to-use testing framework for JavaScript applications
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Command-line interface for running tests in Node.js environments with extensive configuration options, built-in reporters, and watch mode support.
Run QUnit tests from the command line.
# Basic usage
qunit [options] [files...]
# Run all tests in test directory
qunit test/
# Run specific test files
qunit test/unit/math.js test/unit/string.js
# Run tests with glob patterns
qunit "test/**/*.js"Usage Examples:
# Run all JavaScript files in test directory
qunit test/
# Run specific test file
qunit test/unit/calculator.js
# Run multiple test files
qunit test/unit/*.js test/integration/*.js
# Run with glob pattern
qunit "test/**/*-test.js"Configure test execution through command-line options.
# Available CLI options (based on actual implementation)
-f, --filter <filter> # Filter tests by pattern
-m, --module <name> # Run only specified module
-r, --reporter [name] # Specify reporter; list available if no name
--require <module> # Require module before tests (can be repeated)
--seed <value> # Set randomization seed (or 'true' for random)
-w, --watch # Watch files for changes and re-run testsUsage Examples:
# Filter tests by name pattern
qunit --filter "user" test/
# Run only specific module
qunit --module "Authentication" test/
# List available reporters
qunit --reporter
# Use specific reporter (if available)
qunit --reporter console test/
# Watch for file changes
qunit --watch test/
# Require setup module (can be used multiple times)
qunit --require ./test/setup.js --require babel-register test/
# Set randomization seed
qunit --seed 12345 test/
# Generate random seed
qunit --seed true test/Use QUnit CLI programmatically in Node.js scripts.
/**
* Run QUnit tests programmatically
* @param {string[]} files - Array of file patterns
* @param {Object} options - CLI configuration options
* @param {string} [options.filter] - Filter tests by pattern
* @param {string} [options.module] - Run only specified module
* @param {string} [options.reporter] - Specify reporter
* @param {string[]} [options.requires] - Modules to require before tests
* @param {string} [options.seed] - Randomization seed
*/
const run = require('../src/cli/run');
/**
* Run QUnit tests in watch mode
* @param {string[]} files - Array of file patterns
* @param {Object} options - CLI configuration options
*/
run.watch(files, options);Usage Examples:
const run = require('qunit/src/cli/run');
// Run tests programmatically
run(['test/**/*.js'], {
filter: 'integration',
reporter: 'tap',
seed: '12345'
});
// Run in watch mode
run.watch(['test/**/*.js'], {
filter: 'unit',
requires: ['./test/setup.js']
});Specify test files using various patterns.
# Directory patterns
qunit test/ # All files in directory
qunit test/ lib/ # Multiple directories
# File extension patterns
qunit test/*.js # All .js files
qunit test/*.{js,ts} # Multiple extensions
# Glob patterns
qunit "test/**/*.js" # Recursive glob
qunit "test/**/test-*.js" # Pattern matching
# Specific files
qunit test/unit/math.js test/unit/string.jsUsage Examples:
# Run all test files recursively
qunit "test/**/*.js"
# Run only unit tests
qunit "test/unit/**/*.js"
# Run tests with specific naming pattern
qunit "test/**/*-test.js" "test/**/*.test.js"
# Mix directories and patterns
qunit test/unit/ "test/integration/**/*.js"Use different output formats for test results.
# List available reporters
qunit --reporter
# The actual available reporters depend on the implementation
# Check source code or run qunit --reporter to see what's available
# Custom reporter (via require)
qunit --require ./custom-reporter.js test/Default Console Output:
TAP version 13
1..3
ok 1 Math > addition
ok 2 Math > subtraction
not ok 3 String > concatenation
---
message: strings should be concatenated
severity: fail
actual: helloworld
expected: hello world
...
# pass 2
# skip 0
# todo 0
# fail 1With Reporter Option:
The actual output format depends on which reporters are available. Use qunit --reporter to list available options.
Automatically re-run tests when files change.
# Enable watch mode
qunit --watch test/
# Watch with specific patterns
qunit --watch "test/**/*.js" "src/**/*.js"
# Watch with custom reporter
qunit --watch --reporter tap test/Usage Examples:
# Basic watch mode
qunit --watch test/
# Watch source and test files
qunit --watch test/ src/
# Watch with filtering
qunit --watch --filter "unit" test/
# Watch with custom options
qunit --watch --reporter console --verbose test/Load modules before running tests.
# Require single module
qunit --require ./test/setup.js test/
# Require multiple modules
qunit --require ./test/setup.js --require babel-register test/
# Require with environment setup
qunit --require dotenv/config --require ./test/globals.js test/Setup Module Example:
// test/setup.js
const { JSDOM } = require('jsdom');
// Setup DOM environment for browser-like tests
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
global.window = dom.window;
global.document = dom.window.document;
global.navigator = dom.window.navigator;
// Setup global test utilities
global.testHelpers = {
createUser: (name) => ({ id: Math.random(), name }),
mockFetch: () => { /* mock implementation */ }
};
console.log('Test environment initialized');QUnit CLI returns standard exit codes for CI/CD integration.
# Exit codes (standard convention)
0 # All tests passed
1 # One or more tests failed or other errorUsage Examples:
#!/bin/bash
# CI script example
# Run tests and capture exit code
qunit test/
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "All tests passed! ✅"
npm run build
elif [ $EXIT_CODE -eq 1 ]; then
echo "Tests failed! ❌"
exit 1
else
echo "Test runner error (exit code: $EXIT_CODE)"
exit $EXIT_CODE
fiIntegrate with different Node.js environments and tools.
# With environment variables
NODE_ENV=test qunit test/
# With ES modules support
qunit --require esm test/**/*.mjs
# With TypeScript
qunit --require ts-node/register test/**/*.ts
# With Babel
qunit --require @babel/register test/Package.json Integration:
{
"scripts": {
"test": "qunit test/",
"test:watch": "qunit --watch test/",
"test:unit": "qunit --filter unit test/",
"test:integration": "qunit --filter integration test/",
"test:ci": "qunit --reporter tap test/ > test-results.tap"
}
}When no files are specified, QUnit uses a default pattern.
# Default pattern when no files specified
qunit # Equivalent to: qunit 'test/**/*.{js,mjs,cjs}'File Pattern Notes:
'test/**/*.{js,mjs,cjs}' when no files specified/**
* CLI options based on actual implementation (bin/qunit.js)
* @typedef {Object} CLIOptions
* @property {string} [filter] - Filter tests by pattern (-f, --filter)
* @property {string} [module] - Run only specified module (-m, --module)
* @property {string|boolean} [reporter] - Specify reporter (-r, --reporter)
* @property {string[]} [requires] - Modules to require (--require, can be repeated)
* @property {string} [seed] - Randomization seed (--seed)
* @property {boolean} [watch] - Watch mode (-w, --watch)
*/
/**
* The CLI is built using Commander.js and accepts:
* - File arguments: Array of files/patterns to test
* - Options: Filter, module, reporter, require, seed, watch
* - Default pattern: 'test/**/*.{js,mjs,cjs}' when no files specified
*/# Show CLI help
qunit --help
# Show version
qunit --version
# List available reporters
qunit --reporterInstall with Tessl CLI
npx tessl i tessl/npm-qunit