NICTA/nationalmap — pull request #250 by kring (2014-07-25 03:15:32+00:00)
Title: Require-in Cesium and add browserify-based test infrastructure

This pull request is a little scary. I recommend playing with it for a bit to make sure you're happy with it before merging.

Let's start with the gulp tasks:

* `build` - Builds a non-minified version of National Map AND Cesium, together in one JS file (still called `ausglobe.js`). Only the parts of Cesium that we use (directly or indirectly) are pulled in. This task takes about 10 seconds on my system, which is the main reason for the next task.
* `watch` - Starts the same as `build` but then it stays running and watches for changes to any National Map or Cesium source file that was pulled in to `ausglobe.js`. When a change to any of these files is detected, a fast incremental build is automatically kicked off. It takes around a second on my system.
* `release` - Yes, this is back. It does the same as `build` except that it also minifies `ausglobe.js`. Unfortunately my previous attempts to have the same build during development and in production didn't pan out (the release build took too long, gulp just cleverly hid that fact from me). The good news is that we can turn on `mangle` and `compress` when minifying now, and everything still works (thanks to @shunter for figuring this out).

As you may have inferred from the above, we're now explicitly pulling in the parts of Cesium we need with `require` instead of using the complete, built version. I should be able to build Leaflet and our other third-party libraries into the same JS file as well, but I haven't tried yet.

The other major change in this pull request is we can now easily write in-browser tests for National Map using Jasmine. Basic examples are in the `/spec` directory. Just require-in the parts of National Map you're testing and test them with the usual `describe` / `it` / `expect` stuff.

Specs are browserified into a separate JS file from the main part of National Map, called `ausglobe-specs.js`. The `build` and `watch` tasks automatically rebuild the specs JS file as well. You can run the specs by visiting:

http://localhost:3001/SpecRunner.html

You can also build or watch just the app or just the specs by using the `build-app`, `build-specs`, `watch-app`, and `watch-specs` gulp tasks. Interestingly, the specs do NOT depend on the app build (the browserification is totally independent). So if you're just iterating on tests, I recommend running `watch-specs` for fastest cycle time. Note that changes to an existing JS file in the `specs` folder with be picked up automatically by a running `watch`, but if you add a new file you'll need to restart it in order for the new file to be picked up. (I may be able to fix this some day)

In theory we should be able to run these tests on multiple browsers and multiple operating systems using Sauce Labs (which is free for open source projects!), but I haven't quite figured out the logistics yet, since their tutorials are all grunt based. Also, testing WebGL-based functionality will probably be a bit sketchy.

Let me know if you have any questions or concerns!