Here is how I got Nightwatch running on my local machine.
-
Installed Java 8 JDK. JDK != JRE. I run Mac OS El Capitan. If you type java in the terminal and you get an error like
No Java runtime present, requesting install.
then you need the JDK. Go to java.com Downloads section and browse to find the latest version of Java SE Development Kit for your system. As of this writing it's version 8. -
Install Node and Nightwatch globally. If you don't already have Node, install/Update it via download at https://nodejs.org/. Install nightwatch, preferably globally:
$ sudo npm install -g nightwatch
- Configure Nightwatch. Here's a link to our configuration. Our project is named
sa
. This is the root of our Laravel project, and in there you'll find atests
directory. This is the same tests/ directory where our PHPUnit tests for our Laravel app are (i.e. TestCase.php is here). For simplicity, I've removed the php files from that download.
The main places for configuration are:
- package.json "scripts" section. These are npm "commands". For example
npm run test:core
will run our "core" test group. The rimraf part deletes the directory (rm -rf
== 'rimraf') so that only the most recent batch of tests' output will be there. - nightwatch.json - all of it of course. Full docs on this file here. The paths here are relative to the project root.
- globalsModule.js is pretty self-explanatory except for that beforeEach bit. We have a custom route
/testing/refreshdb
(not accessible on prod!) that is just a callartisan migrate:refresh --seed
. The dbrefresh value determines whether the test group will call that beforeEach callback before each test or not. Our "core" group of tests build on each other, so we don't want the db to refresh each time. By the way, you'll see the test groups listed by@tags
in each test. e.g. tests/nightwatch/tests/core/01-create-organization-and-coordinator.js
To run the tests I boot up Homestead, where my app is accessible at http://sa.dev. Then on my Mac, from project root I just do:
$ npm run tests:core