The JavaScript blog.


libraries testing node email modules npm jasmine

Node Roundup: npm CLI Roadmap, Nodemailer, Jasmine-Utils

Posted on .

npm CLI Roadmap

On the npm blog, there's a post about the command-line tool's roadmap:

The first piece of redesign work we're tackling is the npm cache. ... The next goal is to turn it into a module with no dependencies on the rest of npm or npmconf and to test the heck out of it. As npm moves to being a part of the toolchain of front-end developers (who are more interested in shipping features than figuring out what's going on with their OS), it's time to work on making npm easier to understand when things go wrong.

The article also mentions a better search interface, which I'd like to see because the current CLI search implementation is inflexible. It's interesting to read about how the project is evolving away from Isaac's original lightweight implementation intended for experts -- the team behind the project has recognised that npm is used by a diverse range of developers.


Nodemailer (GitHub: andris9 / Nodemailer), License: MIT, npm: nodemailer 1.0 is out! This is a complete rewrite, and partly breaks backwards compatibility so you may need to upgrade carefully:

The new version allows you to write custom plugins for manipulating the outgoing messages. It is also possible to send huge attachments with ease (in the size of tens of gigabytes) thanks to the Streams2 support - even though no one probably needs to send such attachments since probably no e-mail server would accepts these.


Jasmine-Utils (GitHub: mjeanroy / jasmine-utils, License: MIT, npm: jasmine-utils) by Mickael Jeanroy is a set of custom matchers for Jasmine. They're grouped around types, like toBeABoolean and toBeDateBefore. Methods are included for booleans, strings, arrays, dates, objects and functions:

it('should check that an object contains keys', function() {  
  var obj = {
    id: 1,
    name: 'foo'

  expect(obj).toHaveKeys('id', 'name');
  expect(obj).not.toHaveKeys('foo', 'bar');

It also includes some handy spy methods, like jasmine.spyAll and jasmine.spyIf. These allow objects to be watched to ensure the expected methods are run.

The project includes a huge amount of matchers, so if you're using Jasmine you may want to check it out.


ui testing jasmine webworker

Web Worker Contest, Steady.js, Jasmine Integration Tests

Posted on .

Web Worker Contest

The Web Worker Contest, sent in by Stefan Trenkel, is a JavaScript game where two programs compete to conquer a two-dimensional space using simple movement commands.

On a playing area of 100 x 100 square fields two JavaScript programs compete against each other. From a randomly allotted starting point they must conquer as many fields as possible. The winner is who occupies most fields at the end. A move is to conquer from the current field either the upper, lower, right or left adjacent field. The new field can be occupied only if it was not previously occupied by the opponent's program. If a move is possible (the new field is free) the current position changes to the desired field. If a move is not possible (the field is occupied by the opponent or you want to leave the playing area), you stay on the current position. Fields that one has previously occupied can be used again (but do not count double). The programs do not have any information about the playing area.

The contest is based on the Web Worker API:

Your own Web Worker is simply a local JavaScript file with appropriate code. In this case your own Web Worker is not uploaded to the server. This option is primarily for testing and optimizing your own Web Worker. If you want to participate in the WWC you have to upload your Worker on the Upload page.

You can view running games and read more about the concept in the guide.


Steady.js (GitHub: lafikl / steady.js, License: MIT) by Khalid Lafi is a library for elegantly responding to onscroll events. With Steady.js, the onscroll handler collects data, then offloads the work to requestAnimationFrame. It throttles events, and works like @media-query.

Steady.js is based around "trackers": these provide the logic that the data collector uses. An example of a built-in tracker is scrollTop which indicates how far a scrollable element has moved from the top.

Basic usage looks like this:

var s = new Steady({  
  conditions: {
    width: 400,
    scrollX: 0,
    max-bottom: 200
  throttle: 100,
  handler: fn

s.addCondition('scrollX', 0);  

The documentation has an example of a custom tracker that you can extend with your own behaviour.

Jasmine Integration Tests

jasmine-integration by Jordi Noguera is an integration testing extension for Jasmine. It allows you to run tests in browsers by using an iframe, or in headless mode using PhantomJS.

The documentation shows how to use it with Grunt, so you can execute your tests against a browser with grunt jasmine:server, or in headless mode using grunt jasmine:server:ci.

Jordi has written a sample app with tests called node-todo which demonstrates how the same specs can be used for browser testing and headless tests on the command-line.


animation testing angularjs jasmine

MotorCortex.js, Testing AngularJS with Jasmine

Posted on .


Think of dancer dancing or a human just walking the street. It is extremely unnatural to think that each part of the body acts independently. A centralized mechanism controls all parts in order to produce a smooth, elastic and natural movement. The "motor cortex", is the specific part of the brain that does exactly this job.

The idea of declarative templates seems to be spilling into the world of client-side animation. MotorCortex.js (GitHub: andreas-trad / motorcortexjs, License: WTFPL) by Andreas Trantidi is a new library that builds on Velocity.js to provide an animation API that's based on CSS syntax.

With MotorCortex.js, external *.mss files determine animation parameters. These are based on the CSS parameters that are supported by Velocity.js:

  duration: 400;
  top: 300px;

For more examples with the associated CSS and JavaScript, see http://motorcortexjs.com/#examples.

Testing AngularJS with Jasmine

David Posin sent in Angular and Jasmine: Injecting into the test environment. He's been using Jasmine for tests in both Node and client-side JavaScript, so he wanted to use it with Angular as well:

Angular requires a very specific environment in which to function. The result of that can be a significant amount of boilerplate when creating tests for Angular applications in Jasmine. The good news is that the amount of redundancy can be minimized with careful test organization.

The way he does this is by creating embedded suites:

The spec file will have one describe that contains that spec's entire content. Inner describe clauses will be used to manage and break up the tests. Inside of the main over-arching describe we will add variables to contain the services that all the clauses will need.

I too find it frustrating to have to switch my preferred test library because of a framework's design, so it's interesting that he managed to get Jasmine working in the end. It can be quite hard to think the Angular way for relative newcomers.