Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Nightwatchjs Nightwatch Nightwatch CLI

From Leeroopedia
Knowledge Sources
Domains Testing, CLI, Test_Execution
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete CLI entry point for executing Nightwatch.js test suites via Nightwatch.cli() and CliRunner.

Description

Nightwatch.cli() is the primary entry point for command-line test execution. It parses CLI arguments via yargs, then invokes a callback with the parsed argv object. The bin/runner.js entry point calls Nightwatch.cli(), creates a CliRunner instance, sets up configuration, and runs tests. The exit code is 0 for success and 10 for test failures.

Usage

This is invoked automatically when running npx nightwatch from the command line. It can also be used in custom runner scripts that need CLI argument processing.

Code Reference

Source Location

  • Repository: nightwatch
  • File: lib/index.js (lines 231-272)
  • File: bin/runner.js (lines 1-41)

Signature

/**
 * CLI entry point - parses arguments and invokes callback
 * @param {Function} callback - receives parsed argv object
 */
Nightwatch.cli(callback: (argv: Object) => void) -> void

// argv properties:
//   _source: string[]    - test file paths
//   env: string          - browser environment name
//   headless: boolean    - run in headless mode
//   parallel: boolean    - enable parallel execution
//   config: string       - configuration file path
//   reporter: string     - reporter type
//   help: boolean        - show help
//   version: boolean     - show version
//   info: boolean        - show environment info

Import

const Nightwatch = require('nightwatch');

I/O Contract

Inputs

Name Type Required Description
callback Function Yes Function receiving parsed CLI argv object
argv._source string[] No Test file paths to execute
argv.env string No Browser environment (chrome, firefox, etc.)
argv.headless boolean No Run browser in headless mode
argv.parallel boolean No Enable parallel test execution
argv.config string No Path to configuration file

Outputs

Name Type Description
Test execution void Tests are run; results reported
Exit code number 0 = all passed, 10 = failures occurred

Usage Examples

CLI Usage

# Run all tests
npx nightwatch

# Run specific test file
npx nightwatch tests/login.js

# Run with specific browser
npx nightwatch --env firefox

# Run in headless mode
npx nightwatch --headless

# Run tests in parallel
npx nightwatch --parallel

Custom Runner Script

const Nightwatch = require('nightwatch');

try {
  Nightwatch.cli(function(argv) {
    argv._source = argv['_'].slice(0);

    const runner = Nightwatch.CliRunner(argv);

    return runner
      .setupAsync()
      .then(() => runner.runTests())
      .catch((err) => {
        console.error(err);
        runner.processListener.setExitCode(10).exit();
      });
  });
} catch (err) {
  console.error('Failed to start Nightwatch Runner:', err.message);
  process.exit(2);
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment