Problem/Motivation
Now that #2469713: Step 2: Create a JavaScriptTestBase using PhantomJs Driver/Binary is in, we have some way to do end to end testing of our functionality, but if we want to improve our javascript, we better write good tests.
Proposed resolution
The area of javascript testing is scattered to say the least, here is the combination I went with:
- Mocha: Its a testing framework which allows you to define and run tests. Its based upon nodejs by default, but is pretty flexible
- Chai: A assertion library, which is pretty flexible as it supports should, expects and assert notation
- sinon: A mocking framework
Questions
- Do we want unit tests? Everyone agrees with that
- Do we want to add the dependencies into core? Noone wants that, but let's add a shrinkwrap file (lock file): https://docs.npmjs.com/cli/shrinkwrap
- Is CLI based unit testing okay, or do we want more, like browserbased testing with karma? Maybe on the longrun, but let's get something running now and not later
- Is it okay to start without testbot integration? Yes, its okay to make progress, obviously on the longrun we want support on the testbot.
How to use the unit tests
The patch ships with a readme:
### Javascript
+
+First you need to install the dependencies using npm, see (Installing NPM)$https://docs.npmjs.com/getting-started/installing-node].
+
+```
+cd core/tests/js
+npm install
+```
+
+Once you have installed it, you can run the tests using
+
+```
+node_modules/mocha/bin/mocha
+```