Running Cucumber.js Unit Tests
JavaScript unit tests are run in a browser against a test server which actually handles the testing process.
This server allows you to capture a browser to run tests in, loads the test targets to the captured browser, controls the testing process, and exchanges data between the browser and PhpStorm, so you can view test results without leaving the IDE.
The test server does not necessarily have to be on your machine, it can be launched right from PhpStorm
through the Cucumber.js test runner.
Cucumber.js runs tests that are called features
and are written in the Gherkin language. Each feature is described in a separate file
with the extension feature
.
On this page:
Before you start
-
Download and install Node.js. The runtime environment is required for two reasons:
- The Cucumber.js test runner is started through Node.js.
- NPM, which is a part of the runtime environment, is also the easiest way to download the Cucumber.js test runner.
If you are going to use the command line mode, make sure the path to the parent folder of the Node.js executable file and the path to the
npm
folder are added to thePATH
variable. This enables you to launch the Cucumber.js test runner and npm from any folder. - Make sure the Cucumber.js test runner is installed as described in Preparing to Use Cucumber.js Test Runner.
- Install and enable the NodeJS repository plugin as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
- Install and enable the Cucumber.js and Gherkin plugins. The plugins are not bundled with PhpStorm, but they can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins. Once enabled, the plugins are available at the IDE level, that is, you can use them in all your PhpStorm projects.
Creating a Cucumber.js run configuration
- Open the Run/Debug Configuration dialog box by doing one of the following:
- Click the Add button on the toolbar and select the Cucumber.js configuration type. The Run/Debug Configuration: Cucumber.js dialog box opens.
-
In the Feature file or directory text box, specify the tests to run.
Cucumber.js runs tests that are called features
and are written in the Gherkin language. Each feature is described in a separate file
with the extension
feature
. -
In the Executable path text box,
specify the location of the cucumber executable file,
.cmd
,.bat
, or other depending on the operating system used. The location depends on the installation mode, see Installing the Cucumber.js test runner. -
Optionally,
specify the command line arguments to be passed to the Cucumber.js executable file, such as
-r
(--require LIBRARY|DIR
),-t
(--tags TAG_EXPRESSION
), or--coffee
. For details, see Cucumber's native built-in help available through the following command:cucumber-js --help
- Apply the changes and close the dialog box.
Launching unit tests
- To launch the tests according to a run configuration, select the Cucumber.js run/debug configuration from the list on the main toolbar. Then click the Run button to the right of the list.
- The test server starts automatically without any steps from your side. View and analyze messages from the test server in the Run tool window.
- Monitor test execution in the Test Runner tab of the Run tool window as described inMonitoring and Managing Tests.