Zuker Blog

Karmic Challenge: Run Tests With Karma in Internet Explorer on Bamboo Agent

Recently I’ve finished work on small client-side JavaScript library, a simple REST API client, tests for this lib are running with Karma and mocha. I’m using Ubuntu on my laptop so it was not possible to run tests in IE during development, but luckily we have Bamboo as CI server in our company with build agents on Windows vm’s. So plan seemed to be plain and simple: create build job with “karma start” command and collect test reports.
But the real world has made its first adjustments. Dedicating Bamboo 5.6.0 build agent to build plan job doesn’t affects plan branches: if you’ve dedicated agent “Win” to job “Test” of plan “My App Build” with branch “dev” and launch “My App Build” branch dev it will be running on first free suitable agent and will not wait for agent “Win”. So I’ve had to dedicate agent to whole build plan.
Next problem was mysterious and unpredictable. When npm is running under Windows it is trying to use “%APPDATA%/npm” directory, on Windows 2012 Server with domain logon “%APPDATA%” for user “SYSTEM” (system services, including Bamboo agent, are running with this user by default) is “%SYSTEM%\config\systemprofile\AppData\Roaming\” but there was no “npm” dir and npm was crashing with “Error: ENOENT, stat ‘C:\Windows\config\system32\profile\AppData\Roaming\npm”. I’ve manually created this dir and… Surprise! The same “ENOENT” was here! WTF? I’ve tried to change permissions, owner, creating dir from user “SYSTEM” - nothing helped. I’ve leaved this mystery and changed logon user to “Administrator” for Bamboo agent service and “ENOENT” error gone.
It was victory? Not half! Running “npm install” directly from command prompt succeeded. However “npm install” build task failed with error

1
2
npm ERR! ws@0.4.32 install: `(node-gyp rebuild 2> builderror.log) || (exit 0)`
npm ERR! spawn ENOENT

Brief googling led me to this issue after trying all suggested workarounds from comments spawn error was still there. So, remembering that all worked when running “npm install” manually, I’ve turned off Bamboo agent service and ran agent jar directly from Windows Task Scheduler as startup task. Packages install problem gone.
Finally build plan reached “karma start” task. Tests run in Firefox and Chrome was flawless, but some test cases in IE 10 were broken with error “This function is not supported on this system.” referencing to string 9 of sinon.js “functionToString” function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sinon.functionToString = function toString() {
if (this.getCall && this.callCount) {
var thisValue, prop, i = this.callCount;
while (i--) {
thisValue = this.getCall(i).thisValue;
for (prop in thisValue) {
if (thisValue[prop] === this) {
return prop;
}
}
}
}
return this.displayName || "sinon fake";
};

Nothing criminal, a simple comparison. The only reason google gave me was IE 10 bug but I had already ran Bamboo agent as plain application, not service! Again, WTF? Update to IE 11 hasn’t helped. I was going to admit defeat and quarantine failing tests and forget all this challenge. And then I’ve noticed that all failing test cases are using sinon.js spies and chai assertion plugin sinon-chai to check callback function calls, so I’ve made a final step in my “Karmic Challenge” - replaced all spies with plain callback: “asyncAction(spy)” -> “asyncAction(function () { done(); })”. It was all over and now I can sleep quietly.