Intern JS Testing not Publishing JUnit XML File?

Just another random issue I couldn’t find the answer to by googling and finally figured out.

Issue: You have used the Yeoman Dojo generator to init a dojo boilerplate project.

This generator includes the files necessary for using intern to do JS unit testing in your dojo AMD javascript.

You would like to integrate your results into a CI build, and need xml results in order to do that.

You follow the Intern user guide and put the following in the intern config file:

reporters: [
{ id: ‘JUnit’, filename: ‘report.xml’ }
]

You run grunt intern.

You get no report.xml.

You are sad and confused.

😦

Solution:

I suppose that Intern was updated after the yeoman generator was put together. If you look in “node_modules” you’ll see that it includes “intern-geezer”. Not “intern”. I do not know why this is. However, now you know what to do, uninstall “intern-geezer” and install “intern”.

in terminal, within the project folder :
“npm uninstall intern-geezer –save-dev”

then

“npm install intern –save-dev”

Then run your grunt intern task, and witness the new report.xml file created at the project root.

🙂

Dojo Evented Gotcha

As I continue to work through the world of Dojo Dijits, I have run across another gotcha that I couldn’t find any documentation on and therefore only fixed by trial and error. So here’s my contribution to the world by adding this documentation to the internets.

Scenario: You create a custom component, extending the dojo Evented per the documentation:

define(["dojo/Evented"], function(Evented){
  var MyComponent = dojo.declare([Evented], {
    startup: function(){
      // once we are done with startup, fire the "ready" event
      this.emit("ready", {});
    }
  });
}

However, you build upon the component and end up with something like this:

define(["dojo/Evented"], function(Evented){
  var MyModel = dojo.declare([Evented], {
    CURRENT_INDEX_CHANGE:"onCurrentIndexChange",
    currentIndex:0,
    dispatchEvent: function(evt){
      this.emit(evt, {});
    },
    getCurrentIndex:function(){
      return this.currentIndex;
    },
    setCurrentIndex:function(n){
      if(n != this.currentIndex){
         this.currentIndex = n;
         this.dispatchEvent(this.CURRENT_INDEX_CHANGE);
      }
    }
  });
}

AND THEN, you end up getting this error in your browsers console:

TypeError: target.ownerDocument is undefined

ending in bafflement. 😦

Reason:
“dispatchEvent” is used in dojo/on, which Evented extends, causing a conflict.

Solution! Rename your “dispatchEvent” function to something new, so you end up with:

define(["dojo/Evented"], function(Evented){
  var MyModel = dojo.declare([Evented], {
    CURRENT_INDEX_CHANGE:"onCurrentIndexChange",
    currentIndex:0,
    dispatchEventWTF: function(evt){
      this.emit(evt, {});
    },
    getCurrentIndex:function(){
      return this.currentIndex;
    },
    setCurrentIndex:function(n){
      if(n != this.currentIndex){
         this.currentIndex = n;
         this.dispatchEventWTF(this.CURRENT_INDEX_CHANGE);
      }
    }
  });
}

The end.

Building the Dojo Boilerplate

If you’re trying to use https://github.com/csnover/dojo-boilerplate and are getting the following error in the terminal when trying to build:
“-bash: build.sh: command not found”
You probably need to add “./” to “build.sh”. As someone not very Unix savvy this caused me hours of frustration.

So, to elaborate on the instructions under “Quick Start” found in the dojo-boilerplate github project –>

  1. Clone the repository using git clone –recursive.
    [My addition: Or click “clone in desktop” on the right hand side of the git hub page]
  2. Develop your project in src/ until it is amazing.
  3. Run build.sh, which will create an awesome optimised build in dist/.
    [My addition: Do the following:

    1. Open the Terminal (assuming you’re on a Mac – sorry, can’t really help if you’re not)
    2. cd to the boilerplate directory – specifically, you can type “cd” and then, drag the dojo-boilerplate directory into the terminal. This is a shortcut to cd to that directory. Alternatively, you can explicitly type out the directory path, as in “cd /User/uName/dojo-boilerplate”, where “/User/uName/dojo-boilerplate” is the path to your dojo-boilerplate.
    3. then type “./build.sh” into the terminal.
    4. you should then see a ton of logs showing that something is happening. Be patient, after about a minute, you will see “Build complete”. Now everything should be compiled in the “dist” folder that was created.
  4. Upload dist/ for millions of people the world over to enjoy.