Unit testing OAuth JS with Mocha

I'm working on a JS based project that runs off GAE and part of the code gets the user's avatar using OAuth from Facebook, Twitter or Google. I'm trying to write tests in Mocha in order to test this but I'm running into some problems.

The code works when I test it in the front end, and the way I envisaged it to work would be to use ZombieJS to run the app on GAE's dev_appserver.py, fire the OAuth functions, fill in the appropriate auth stuff and then complete the test by returning the image URL.

However the first hurdle I've got is that it appears that NodeJS's server is not allowing GAE's server to run on the same IP address. For example:

exec 'dev_appserver.py .', ->
    console.log arguments

This returns the error 'Address already in use'. How can I get around this apart from running it on a different machine? Is it possible to tell NodeJS to not reserve the whole IP and just a port? I'm running GAE on 8080 and it works fine when it isn't invoked by NodeJS.

The second problem is ZombieJS. I'm trying to figure out a way I can listen to when new windows are opened and, essentially, tail the console of the browser. I've started two discussions on the Google group but no one has responded yet (https://groups.google.com/forum/?hl=en#!topic/zombie-js/cJklyMbwxRE and https://groups.google.com/forum/?hl=en#!topic/zombie-js/tOhk_lZv5eA)

While the latter isn't as important as I can find ways around it (I hope), the former is the main issue, so I'd greatly appreciate any direction on how to resolve this address conflict.

Here's my NodeJS script:

exec = ( require 'child_process' ).exec
fs = require 'fs'
should = require 'should'
yaml = require 'yaml'
Zombie = require 'zombie'

common  = require '../../static/assets/js/common'

url = 'ahmeds.local'

browser = new Zombie()
config = null
consoleCb = 'function consoleSuccess(){console.log("success",arguments)}function consoleFailure(){console.log("failure",arguments)}'

browser.debug = true
browser.silent = false

fs.readFile '../../config.yaml', (error, data) ->
    config = yaml.eval data.toString 'ascii'

    exec 'cd ../../ && dev_appserver.py -a ' + url + ' .', ->
        console.log arguments

        # browser.visit config.local.url, ->
        browser.visit 'http://' + url + ':8080', ->
            browser.evaluate consoleCb

            browser.evaluate 'profileImage("facebook",consoleSuccess,consoleFailure)'

            console.log browser.window.console.output

I have only limited familiarity with NodeJS, but I just tested running a NodeJS server and App Engine local dev server on the same machine — it works just fine. Without seeing your NodeJS code, I'm guessing you're also trying to run NodeJS on port 8080, and so the App Engine server complains when it's started (8080 is the default, and you noted it's the port you are using).

Try passing --port=8081 (or some other port) to your invocation of dev_appserver.py and it should resolve the conflict.

Nothing in the code you've shown (other than the invocation of dev_appserver) should even be listening on any port (unless zombie implements a "server" for remote debugging or something like that). It looks like the port conflict is coming from somewhere else.

Note that zombie's own Mocha test framework does set up an express server, so if you're using it or code lifted from it, that might be doing it.

What does netstat have to say about who's binding to what port?