Dev ~ gnss testing - GeoscienceAustralia/egeodesy GitHub Wiki

Testing setup is proving to be a source of an unneeded amount of frustration. You find that you add a dependency and then suddenly you see something like the following after running tests:

START:
20 12 2016 11:28:09.597:WARN [web-server]: 404: /base/node_modules/raf.js
Chrome 53.0.2785 (Linux 0.0.0) ERROR: Error{originalErr: Error{}}
  About component
    ✔ should work

Finished in 0.501 secs / 0.977 secs

SUMMARY:
✔ 1 test completed

WTF, there are 35 tests.

Worse still, as far as Karma is concerned, the included test runs and passes. So our build system doesn't see that there is anything wrong and we continue our work none the wiser.

Here are the possible changes required:

Runtime configuration

This is not about the tests though if the web server isn't starting then this is likely to be where a change is required.

Add something like the following to tools/config/project.config.ts.

      {src: 'jsonix/jsonix.js', inject: 'libs'},

This seems to be needed when there is a Javascript library without a typing library (ala typings.json) - notice that despite all the dependencies we have there isn't much in this file.

Testing dependency

Add an inclusion for the *js to /karma.conf.js. Eg.

      { pattern: 'node_modules/performance-now/**/*.js', included: false, watched: false },

Testing file mapping

When you see the test fail with:

20 12 2016 11:28:09.597:WARN [web-server]: 404: /base/node_modules/raf.js

Then a mapping needs to be setup to this. Note that the file doesn't exist and hence why a mapping is needed. Add something like the following to /test-config.js:

      'raf': 'raf/index',

Now when the mapping / substitution is done the path becomes:

/base/node_modules/raf/index.js

Which if you inspect the node_modules/raf directory you will notice is correct.