Troubleshooting missing tests in Atlassian Bamboo

Our team at work uses Bamboo for our continuous integration tasks for our sites. We have an AngularJS 1.5 app that I’m primarily responsible for, and, as such, have been working to build out our suite of unit tests for the application. My local development setup includes a terminal window that runs these tests every time I save a JS file anywhere in the application.

I have the Karma config set up to use the ‘jUnit’ reporter to output a jUnit-compatible test report after the tests complete. The Bamboo build job is configured to read the resulting XML file and include the results of the test run in the build job result. That’s been working smoothly for several months.

Recently, however, I noticed a discrepancy between the number of tests reported being run in my terminal window and the number of tests that Bamboo reported in the build job result. The number Bamboo reported was consistently 6 fewer than my terminal reported. Project deadlines being what they are, I didn’t pay this too much mind for a few weeks after I noticed it, but last week I just couldn’t ignore it any more so I began digging.

In importing the jUnit XML file, Bamboo lists gives you the ability to list out all the tests that it runs in a very easy to read format. Our individual test specs aren’t that large so it was a fairly easy task to look at my userSpec.js file and count the number of tests and compare that against the Bamboo report. It didn’t take long to find the specs that had more tests in it than Bamboo was reporting.

In ‘BDD-style’ unit tests, your tests look something like this:

describe( 'new', function(){
 
	it('should return a generic user object when an invalid type is requested', function() {
		var user = UserService.new('someBogusUserType', {});
		expect(user.userType).toEqual('user');
	});
 
});

What I found was that I had some “copy/paste” issues. I’d copied an ‘it()’ function block and changed out the innards, but had failed to change the descriptor text (the ‘should return…’ text above). This didn’t matter to the ‘progress’ reporter that is also configured in the Karma config as it just listed the raw number of tests run and any failures.

However, evidently that descriptor text is the only unique thing that Bamboo has available to determine the number of tests run. The second instance of the same descriptor text was replacing the previous instance from the jUnit report. Once I’d made sure that the descriptor text for every ‘it()’ function was unique, Bamboo started reporting the same numbers of tests run/passed as my local terminal window reported while developing.

Feel free to insert your own anecdote about the evils of copy/paste here…

Experimenting with HTML and Javascript development in Adobe AIR

This is a rather long post detailing some of the things I learned this weekend while creating my first “real” Adobe AIR application that joins my love of programming with another hobby that I have enjoyed for several years.

Those of you that know me very well might remember that one of my hobbies is amateur radio. There are many facets to the ham radio hobby and one of them that I’ve been involved with over the last few years combines radios and GPS data into a real-time position reporting system called Automatic Position Reporting System (APRS). To make a long story short, people equipped to use this system have specialized radios in their vehicles that read positional data from GPS units and transmit it out over certain frequencies periodically. Usually, these information packets eventually find their way to a series of servers that forward the data to connected clients for display on whatever mapping system the client has available locally.

This weekend, I spent some time creating an Adobe AIR application written in HTML and Javascript that connects to one of these servers and plots the position reports on a Google map. I haven’t had a chance to do much development with AIR up to now so I thought this would be a good exercise to see if I could create a usable solution.

Read More

Be careful with the ‘local’ scope when migrating from CF8 to CF9

One of the really nice “fixes” included in ColdFusion 9 from a developer’s perspective is the inclusion of an implicit “local” variable scope into which variables created within the body of a <cffunction> tag are placed by default. Previously, developers had to manually add a “var” keyword to variables that should only exist within the confines of the function.

One of the ways of simplifying this that gained some traction among various developers prior to the release of ColdFusion 9 was to “var” a single variable at the top of the function as an empty structure then store any additional variables needed in the function inside it. Many folks, myself included, named this structure “local” so that it would be readily apparent that the values inside were local to that function. This approach worked fine and dandy on ColdFusion 8 and below.

Read More

jQuery head-scratcher and lesson learned

As I mentioned in my last post, I’m working on a pet project in my spare time. It uses jQuery in various places including in the site design template that I purchased to use with the site. The template uses jQuery to expand and collapse menu items in the left sidebar to show sub items for that selection. Because of this, jQuery and a javascript file named custom.js was included in the template. After breaking the template apart to work inside my ModelGlue application, I started implementing some other features that used jQuery with their own associated javascript files, one of which was cfUniform.

As soon as I put the cfUniform code into the page, I started getting javascript errors in the console pane of Firebug. The error would state something similar to “$(document) not a function” or “$ not a function”. Now, I’ve not had a ton of experience with jQuery, but I have used several pre-built jQuery plugins in sites before and I had seen errors similar to this. Normally this error is caused by one of two issues. Either a) you’ve forgotten to include the script block to load the jQuery library or b) your code is loading the jQuery library twice.

I was able to use Firebug to verify that I was indeed loading it and loading it only once but couldn’t for the life of me figure out why I was getting an error. Obviously cfUniform wasn’t really at fault (the error pointed to a line in one of the cfUniform javascript files) so I knew it had to be something on my side. I did some searching on the phrase and found some discussions around jQuery’s noConflict() feature that allows you to reference jQuery with a notation other than using the familiar “$”.

After reading for a while, I opened the custom.js file that came with the site template and found the code below:

1
2
3
4
jQuery.noConflict();
jQuery(document).ready(function(){
   //contents snipped
}

Since I’m not using any other javascript libraries in this application that might conflict with using the “$” to access jQuery, I removed the noConflict() line, but that didn’t fix my problem. On a hunch I did a search/replace through the custom.js file replacing “jQuery(” with “$(” so that references to the jQuery library in this file would be accessed with the same syntax as in all the other javascript files. Lo and behold, all my errors in Firebug’s console went away and CFUniform began behaving as expected.

While I don’t understand all the underpinnings of why this worked, I’ll take it as my “lesson for the day” that in the future I need to always make sure that all the various jQuery plugins and code that is used in my applications need to reference the jQuery library with the same syntax.

Free and easy way to play MP3 files in your web pages

One of my current clients recently commissioned me to write a feature for their site that allows visitors to listen to snippets of MP3 tracks that they sell directly from within the product’s “detail” page. In my particular situation, one of the requirements was to use the design commissioned by a separate design firm. In doing some research I found a few different open source methods of accomplishing this. The one that turned out to be the best fit for our situation was an Adobe Flash-based application called NiftyPlayer.

NiftyPlayer is a free, open source Flash file that you can embed into your page and play MP3 files without worrying about what audio player is installed on the visitor’s machine. The best part for my situation is that the player is completely controllable through Javascript. That means that I could completely “hide” the UI provided by the Flash file by setting the height and width of the Flash object to zero and use custom javascript methods to craft my page to do exactly what I wanted it to do.

Read More