使用方法
Nightwatch には、テストの実行と有用な出力の生成を容易にするコマンドラインテストランナーが含まれています。ランナーのインストール方法の詳細については、インストールセクションを参照してください。インストールの種類に応じて、テストランナーを使用する方法はいくつかあります。
グローバル
Nightwatch をグローバルにインストールした場合(-g
オプション付き)、バイナリnightwatch
はどこからでも使用できます。
nightwatch [source] [options]
プロジェクト固有
プロジェクトの依存関係として Nightwatch をインストールした場合は、node_modules/.bin
フォルダーからバイナリを参照するか、NPM によって提供される npx
コマンドを使用できます。
npx nightwatch [source] [options]
または直接
./node_modules/.bin/nightwatch [source] [options]
Windows 上で
node node_modules/.bin/nightwatch [source] [options]
テストソース
オプションのsource
引数は、1つ以上のファイル、またはフォルダ全体にすることができます。これは、src_folders
設定で設定された値を上書きします。
単一テストの実行
nightwatch tests/one/firstTest.js
2つの個々のテストの実行
nightwatch tests/one/firstTest.js tests/secondTest.js
1つの個々のテストと1つのフォルダの実行
nightwatch tests/one/test.js tests/utils
ランナーオプション
テストランナーは、多数の CLI 引数をサポートしています。すべてを表示するには、実行します。
nightwatch --help
Usage: ./node_modules/.bin/nightwatch [source] [options]
Main options:
--env, -e ........ Specify the testing environment to use. [default: "default"]
--config, -c ..... Path to configuration file; nightwatch.conf.js or nightwatch.json are read by default if present. [required] [default: "./nightwatch.json"]
--test, -t ....... Runs a single test.
--testcase ....... Used only together with --test. Runs the specified testcase from the current suite/module.
--mocha .......... Set the test runner to use Mocha.
--timeout ........ Set the global timeout for assertion retries before an assertion fails.
--reuse-browser .. Use the same browser session to run the individual test suites
--parallel ....... Enable running the tests in parallel mode, via test workers; can also specify de desired workers count (e.g. --parallel=4)
--headless ....... Launch the browser (Chrome, Edge or Firefox) in headless mode.
--devtools ....... Automatically open devtools when launching the browser (Chrome, Edge, or Safari).
--verbose ........ Displays extended HTTP command logging during the test run.
--fail-fast ...... Run in "fail-fast" mode: if a test suite cannot be started, the rest will be aborted
--list-files ..... Shows list of files present in the project.
Tags & filtering:
--group, -g ...... Runs a group of tests (i.e. a folder)
--skipgroup, -s .. Skips one or several (comma separated) group of tests.
--filter, -f ..... Specify a filter (glob expression) as the file name format to use when loading the files.
--tag, -a ........ Only run tests with the given tag.
--skiptags ....... Skips tests that have the specified tag or tags (comma separated).
Test Filters – Mocha only:
--grep ........... Only run tests matching this string or regexp.
--fgrep .......... Only run tests containing this string.
--invert ......... Inverts --grep and --fgrep matches.
Retrying:
--retries ........ Retries failed or errored testcases up <n> times.
--suiteRetries ... Retries failed or errored testsuites up <n> times.
Reporting:
--output, -o ..... Where to save the (JUnit XML) test reports.
--reporter, -r ... Name of a predefined reporter (e.g. junit) or path to a custom reporter file to use. [default: ["junit","json","html"]]
--open ........... Opens the HTML report generated in the default browser at the end of test run
Component Tests:
--debug .......... Automatically pause the test execution after mounting the component and open the Nightwatch debug REPL interface.
--story .......... Allows to specify which story to run from the current file (when using Storybook or JSX written in component story format)
--preview ........ Used to preview a component story/test; automatically pause the test execution after mounting the component.
Info & help:
--help, -h ....... Shows this help (pass COLORS=0 env variable to disable colors).
--info ........... Shows environment info, i.e. OS, cpu, Node.js and installed browsers.
--version, -v .... Shows version information.
推奨コンテンツ