CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-qunit

The powerful, easy-to-use testing framework for JavaScript applications

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

configuration.mddocs/

Configuration

Flexible configuration system for controlling test execution, filtering tests, setting timeouts, customizing behavior, and configuring reporters.

Capabilities

Test Execution Configuration

Control how tests are executed and managed.

/**
 * @typedef {Object} QUnitConfig
 * @property {boolean} autostart - Automatically start tests when page loads (default: true)
 * @property {boolean} reorder - Run failed tests first in subsequent runs (default: true)
 * @property {boolean} requireExpects - Require assert.expect() calls in all tests (default: false)
 * @property {number} testTimeout - Global test timeout in milliseconds
 * @property {string|boolean} seed - Seed for randomizing test order
 * @property {boolean} failOnZeroTests - Fail when no tests are run (default: true)
 */
QUnit.config.autostart
QUnit.config.reorder
QUnit.config.requireExpects
QUnit.config.testTimeout
QUnit.config.seed
QUnit.config.failOnZeroTests

Usage Examples:

import QUnit from "qunit";

// Disable autostart for manual control
QUnit.config.autostart = false;

// Load resources then start
loadTestDependencies().then(() => {
  QUnit.start();
});

// Require expect calls in all tests
QUnit.config.requireExpects = true;

// Set global timeout
QUnit.config.testTimeout = 2000; // 2 seconds

// Use specific seed for reproducible test order
QUnit.config.seed = "12345";

Test Filtering Configuration

Filter which tests run based on various criteria.

/**
 * Test filtering configuration properties
 */
QUnit.config.filter    // Filter tests by name pattern (string or regex)
QUnit.config.module    // Run only tests in specified module
QUnit.config.moduleId  // Run only modules with specified IDs (array)
QUnit.config.testId    // Run only tests with specified IDs (array)

Usage Examples:

// Run only tests matching pattern
QUnit.config.filter = "user";

// Run only specific module
QUnit.config.module = "Authentication";

// Run specific tests by ID
QUnit.config.testId = ["test-123", "test-456"];

// Run specific modules by ID
QUnit.config.moduleId = ["module-auth", "module-users"];

Display Configuration

Customize how test results are displayed in browser environments.

/**
 * Display configuration properties for HTML reporter
 */
QUnit.config.altertitle  // Modify document title on completion (default: true)
QUnit.config.collapse    // Collapse passing tests in HTML reporter (default: true)
QUnit.config.scrolltop   // Scroll to top when tests complete (default: true)
QUnit.config.hidepassed  // Hide passed tests in HTML reporter

Usage Examples:

// Keep document title unchanged
QUnit.config.altertitle = false;

// Show all tests expanded
QUnit.config.collapse = false;

// Hide passing tests to focus on failures
QUnit.config.hidepassed = true;

// Don't scroll to top when done
QUnit.config.scrolltop = false;

Development Configuration

Settings for development and debugging scenarios.

/**
 * Development and debugging configuration properties
 */
QUnit.config.noglobals       // Check for global variable leaks (default: false)
QUnit.config.notrycatch      // Disable try-catch for easier debugging (default: false)
QUnit.config.maxDepth        // Maximum depth for object comparison (default: 5)
QUnit.config.countStepsAsOne // Count assert.step() as single assertion (default: false)
QUnit.config.updateRate      // Rate for UI updates in milliseconds (default: 1000)

Usage Examples:

// Enable global leak detection
QUnit.config.noglobals = true;

// Disable try-catch for debugging
QUnit.config.notrycatch = true;

// Increase comparison depth for complex objects
QUnit.config.maxDepth = 10;

// Count multiple steps as one assertion
QUnit.config.countStepsAsOne = true;

Reporter Configuration

Configure built-in reporters and their behavior.

/**
 * Reporter configuration object
 */
QUnit.config.reporters = {
  console: false,  // Enable console reporter for Node.js
  tap: false      // Enable TAP reporter
}

Usage Examples:

// Enable console reporter in Node.js
QUnit.config.reporters.console = true;

// Enable TAP output
QUnit.config.reporters.tap = true;

// Disable all built-in reporters
QUnit.config.reporters.console = false;
QUnit.config.reporters.tap = false;

Runtime Configuration Access

Access current test execution state and statistics.

/**
 * Runtime configuration and state (read-only during execution)
 */
QUnit.config.current   // Currently running test context
QUnit.config.modules   // Array of all registered modules
QUnit.config.stats     // Test execution statistics
QUnit.config.storage   // Storage backend for test state
QUnit.config.started   // Timestamp when tests started
QUnit.config.blocking  // Whether test execution is paused
QUnit.config.queue     // Internal test queue

// Statistics object structure:
QUnit.config.stats = {
  all: 0,       // Total assertions
  bad: 0,       // Failed assertions  
  testCount: 0  // Total tests
}

Usage Examples:

QUnit.test("access runtime config", function(assert) {
  // Get current test info
  const currentTest = QUnit.config.current;
  assert.ok(currentTest, "current test is available");
  
  // Check total test count
  assert.ok(QUnit.config.stats.all >= 1, "at least one test registered");
  
  // Access module information
  const modules = QUnit.config.modules;
  assert.ok(Array.isArray(modules), "modules array is available");
});

URL Parameter Configuration

Configure tests via URL parameters in browser environments.

// URL parameters automatically update QUnit.config
// Examples:
// ?filter=user          - Filter tests by "user"
// ?module=Auth          - Run only "Auth" module  
// ?noglobals=true       - Enable global leak detection
// ?notrycatch=true      - Disable try-catch
// ?seed=12345          - Set specific seed
// ?hidepassed=true     - Hide passed tests

Usage Examples:

<!-- URL parameter examples -->
<a href="test.html?filter=login">Run login tests</a>
<a href="test.html?module=UserManager">Run UserManager module</a>
<a href="test.html?noglobals=true&notrycatch=true">Debug mode</a>

Configuration Initialization

Set configuration before tests run.

/**
 * Extend configuration with custom options (deprecated in QUnit 3.0)
 * @param {Object} options - Configuration options to merge
 * @param {boolean} [priority] - Whether to override existing values
 * @deprecated Use Object.assign instead
 */
QUnit.extend(options, priority)

Usage Examples:

// Set multiple configuration options
QUnit.extend({
  autostart: false,
  requireExpects: true,
  testTimeout: 5000,
  noglobals: true
});

// Override existing configuration
QUnit.extend({
  filter: "critical"
}, true);

Storage Configuration

Configure persistent storage for test state.

/**
 * Storage backend interface (defaults to sessionStorage in browsers)
 * @typedef {Object} Storage
 * @property {Function} getItem - Get stored value
 * @property {Function} setItem - Set stored value  
 * @property {Function} removeItem - Remove stored value
 * @property {Function} clear - Clear all stored values
 */
QUnit.config.storage = {
  getItem(key) { /* ... */ },
  setItem(key, value) { /* ... */ },
  removeItem(key) { /* ... */ },
  clear() { /* ... */ }
}

Usage Examples:

// Custom storage implementation
QUnit.config.storage = {
  data: new Map(),
  
  getItem(key) {
    return this.data.get(key) || null;
  },
  
  setItem(key, value) {
    this.data.set(key, value);
  },
  
  removeItem(key) {
    this.data.delete(key);
  },
  
  clear() {
    this.data.clear();
  }
};

Environment Variables and URL Parameters

QUnit can be configured via environment variables (Node.js) or URL parameters (browser):

// Environment variables (Node.js)
process.env.qunit_config_autostart = 'false'
process.env.qunit_config_filter = 'login'
process.env.qunit_config_module = 'Authentication'
process.env.qunit_config_noglobals = 'true'
process.env.qunit_config_notrycatch = 'true'
process.env.qunit_config_reporters_console = 'true'
process.env.qunit_config_reporters_tap = 'true'

// URL parameters (browser)
// ?autostart=false&filter=login&module=Auth&noglobals=true

Configuration Object Structure

The complete QUnit.config object contains:

/**
 * Complete configuration object structure based on QUnit v2.24.1
 */
QUnit.config = {
  // Test execution control
  autostart: true,
  reorder: true,
  requireExpects: false,
  testTimeout: undefined,
  seed: undefined,
  failOnZeroTests: true,
  
  // Test filtering
  filter: '',
  module: undefined,
  moduleId: undefined,
  testId: undefined,
  
  // Display options  
  altertitle: true,
  collapse: true,
  scrolltop: true,
  hidepassed: undefined,
  
  // Development options
  noglobals: undefined,
  notrycatch: undefined,
  maxDepth: 5,
  countStepsAsOne: false,
  updateRate: 1000,
  
  // Reporter configuration
  reporters: {},
  
  // Runtime state (read-only)
  current: null,
  modules: [],
  stats: { all: 0, bad: 0, testCount: 0 },
  storage: window.sessionStorage || null,
  started: 0,
  blocking: true,
  
  // Internal properties
  currentModule: {},
  globalHooks: {},
  pq: null,
  queue: [],
  callbacks: {},
  urlConfig: []
}

Install with Tessl CLI

npx tessl i tessl/npm-qunit

docs

assertions.md

cli.md

configuration.md

error-handling.md

events.md

hooks.md

index.md

test-definition.md

test-flavors.md

utilities.md

tile.json