The Gateway Drug to Continuous Integration

Sometimes I come onto a project and there is no continuous integration or tests. I like working with tests and using a continuous integration setup, especially when working with others. I also think that a project's quality will increase and the speed also increases when we get automated feedback from continuous integration.

Typically a good first step for me is to get some basic tools running. Before I even write any tests, I get some basic sanity checks in place. If I am running in a Ruby environment, for example, I may run some static analyzers and fail the build if they fail. I might also check that every Ruby file that we have at least passes ruby -c (which checks for syntax errors. In JavaScript-land, this might take the form of jshint or another linter. In compiled languages, just ensuring that you can compile your code might be enough.

Read on →

Express Route Parameter Ordering

I was trying to use two Express param functions in one route, and one of the param functions needed the other param to be loaded. For example, if I have the route file:

    // route file
    app.route('/api/v1/toolboxes/:toolboxId/tools/:toolId')
    ...
    app.param('toolboxId', controller.loadToolbox);
    ...
    app.param('toolId', controller.loadToolAndEnsureFromToolbox);

And an associated controller:

    exports.loadToolbox = function(req, res, next, id) {
        // load toolbox from Mongoose into req.toolbox
        req.toolbox.maker = req.toolbox.maker || 'Stanley';
    };

    // controller
    exports.loadToolAndEnsureFromToolbox = function(req, res, next, id) {
        Tool.findAsync({
            _id: id,
        }).then(function(tool) {
            if (!tool) {
                res.status(404).send("Tool not found");
            } else if (tool.maker !== req.toolbox.maker) {    // <<<<<
                res.status(403).send("This tool isn't from the right maker!");
            } else {
                req.tool = tool;
                ...
                next();
            }
       });
       ...
    };

I wasn't positive that toolbox would always be loaded when I wanted to check it in tool. (This is kind of a strange example, but it resembles a problem that I was trying to solve.)

Read on →

Testing MEAN Apps With Javascript

On March 18th, I presented "Testing MEAN Apps With Javascript" to the Indy.JS meetup group. The room was packed as we covered the basics of why we do developer testing, and how to test apps that are built with Mongo, Angular, Express, and Node. Most of the code was devoted to showing how to test Mongoose models, Express routes and controllers, and Node functions with Mocha and Sinon. Here is the slide deck (written with reveal.js):

Full size slides

Some supporting comments

Some comments from the slides (in my super-secret speaker deck…):

What is testing?

You already do testing, probably on at least a manual basis.

For the purposes of this talk, testing is automated developer testing. These are tests that you write to verify the code that you write and to move more quickly.

Read on →

Debugging and Fixing Local Karma PhantomJS Issue

Debugging and Fixing Local Karma PhantomJS Issue

Using Karma for a client AngularJS project. Technically there is only one Karma test (a stub success test) since we haven't gotten around to using that yet. But it is set up and part of our test build chain. Using Mocha for Node tests (controllers, models) and Protractor for end-to-end testing.

So I am running Karma locally, and all of a sudden getting some PhantomJS issues. The results look something like:

$ grunt test:karma --debug
Running "env:test" (env) task
[D] Task source: myproject/node_modules/grunt-env/tasks/env.js

Running "karma:unit" (karma) task
[D] Task source: myproject/node_modules/grunt-karma/tasks/grunt-karma.js
INFO [karma]: Karma v0.12.23 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
INFO [launcher]: Trying to start PhantomJS again (1/2).
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
INFO [launcher]: Trying to start PhantomJS again (2/2).
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
ERROR [launcher]: PhantomJS failed 2 times (timeout). Giving up.
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

It would try again after a bit and continually fail. The continuous integration server and other developers' machines are working just fine. Usually you hear "works on my machine". Well in this case, it didn't work on my machine, but worked everywhere else.

Read on →

Blog Changes Afoot

Hey there, loyal blog reader! I wanted to tell you about some exciting changes that I have in the works for my blog. And, no, this is not Our Incredible Journey. :)

Domain change

My blog was previously called "22 Idea Street". This was a name I mostly arbitrarily chose in 2008. Back in 2012, a movie called "21 Jump Street" was released, followed by a sequel "22 Jump Street". Based on the similarity to these movies, and the arbitrariness of the name, I am deciding to rebrand the blog's domain to avoid any confusion or unwanted connection. I have never seen the movies and have no idea what they are about. :) I was kind of bummed when I saw this and got less excited about writing here.

Read on →