The last type of tests we can write in Drupal 8 is the JavaScript-powered Functional tests. FunctionalJavascript tests are useful when we want to test more dynamic client-side functionality such as JavaScript behaviors or Ajax interactions.
They are an extension of the regular Functional tests but which use the Phantom.js driver instead of Goutte for Mink in emulating the browser. This also means that in order to run these tests we need to install Phantom.js.
Installing Phantom.js is very simple. We have to go to the website (http://phantomjs.org/download.html) and download the package somewhere onto our system. Since we are using a Linux system so we can pull the archive into our home folder (the following link may change for you depending on the version):
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
Then we can untar the archive:
tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2
This will unpack the archive into the current folder. And that is it.
To run Phantom.js, we need to run the executable with the following command (from within the Drupal core folder):
~/path/to/the/phantomjs/executable --ssl-protocol=any --ignore-ssl-errors=true ../vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768
This will start Phantom.js in the current terminal window where we can see the output as tests are running. So to run tests, we need to open another terminal window. Alternatively, we can start it and have it run in the background by appending the following to the preceding command:
2>&1 >> /dev/null &
Now we can also run the tests in the current window as Phantom.js runs in the background.
Now that we have Phantom.js running, we can write some tests.