January 09, 2014

PhantomJS and Node.JS

I'm setting up a guide for contributing to PencilCode.

There are now integration tests. In about 20 seconds, the "grunt test" command starts a local development server, starts a headless webkit, and tests most of the core functionality on the website, including browsing users and directories, loading, editing, running, saving, and deleting programs, and using passwords to log in. You get this all for free by just installing node.js and the grunt build tool, and building the source.

The integration tests look like this: edit_code.js - they are low-level but surprisingly clean and quick. The tests are designed to be run by mocha (a command-line javascript test runner), and they depend on node-phantom-simple, which is the lightest-weight headless webkit I could drive from a node.js build environment. The Gruntfile sets up everything. One of the curious things is that the development server actually runs as a proxy server. This allows it to intercept test-browser requests to full DNS names even though it doesn't own the DNS name.

Why Tests are Awesome

The test setup is designed to maximize developer productivity: the default test target runs tests very similar to production, with all the code compiled and minified, but the "devtest" target runs the same tests directly against unminified unoptimized source code, for easier debugging.

The beauty of a good integration test is that the code can now be aggressively changed without fear that the change will break something important. If some change breaks something, we can know in 20 seconds.

Right now my integration tests run quickly, because my test matrix is small. As the test matrix grows larger, many open source projects use jquery-turtle as well; then it will be time to refactor the code so some interesting features can be added.

Posted by David at January 9, 2014 07:29 PM
Comments

Hi

Posted by: at November 22, 2014 10:08 AM
Post a comment









Remember personal info?