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 Component CLI

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

Overview

CLI command for executing Nightwatch.js component tests with the --component flag and dev server integration.

Description

Running npx nightwatch --component activates component testing mode. This starts the configured development server (Vite by default), compiles the test files and their component imports, serves them to the browser, and executes the tests. The same bin/runner.js entry point and Nightwatch.cli() function are used, with the --component flag modifying the execution pipeline to include dev server management.

Usage

Run component tests from the CLI with the --component flag. Specify the test directory or files as arguments.

Code Reference

Source Location

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

Signature

npx nightwatch [test-files] --component [options]

# Options:
#   --component       Activate component testing mode
#   --env <name>      Browser environment
#   --headless        Run in headless mode

Import

# CLI command - no import required
npx nightwatch test/component --component

I/O Contract

Inputs

Name Type Required Description
--component flag Yes Activates component testing mode
test files string No Path to component test files (default: configured src_folders)
--env string No Browser environment name
--headless flag No Run browser in headless mode

Outputs

Name Type Description
Dev server started Process Vite/Webpack dev server running
Test results Pass/Fail Component test results
Exit code number 0 = success, 10 = failures

Usage Examples

Run Component Tests

# Run all component tests
npx nightwatch test/component --component

# Run specific component test
npx nightwatch test/component/Button.test.js --component

# Run in headless mode
npx nightwatch test/component --component --headless

# Run with specific browser
npx nightwatch test/component --component --env firefox

Related Pages

Implements Principle

Requires Environment

Page Connections

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