Access Native Node.js Modules within Intern
Intern is an awesome unit and functional test suite from SitePen. I've been using this utility extensively over the past year, writing tests to make sure MDN's front-end is in good shape after code merges and pushes.
Sometimes when writing tests I'll want to make use of a node module to accomplish a test task, like making an HTTP request or getting environment information. It isn't as easy as making the same dependency path you would if you were writing a node module -- you're using the Dojo loader so you'll need to require those modules a bit differently:
define([
'intern/dojo/node!http',
'intern/dojo/node!process'
], function(http, process) {
// http and process now available from the Node.js environment
});
The dojo/node
Dojo module gives your Intern test suite the ability to access native Node.js modules!
![39 Shirts – Leaving Mozilla]()
In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...
![CSS Animations Between Media Queries]()
CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...
![Create Classy Inputs Using MooTools’ OverText]()
The MooTools More library is a goldmine. A treasure chest. Pirates booty, if you will (and, of course, I will). More is full of plugins that add a lot of class and functionality to your website with minimal effort.
![Scrolling “Go To Top” Link Using Dojo]()
One of the most popular code snippets of posted on my blog has been the scrolling "Go To Top" link snippet. The premise of the snippet is simple: once the user scrolls an element (usually the BODY element) past a given threshold, a "Go...
Seems like it’d be a lot easier to use the default require/exports/module style, so that your test module feels a lot more like Node. The above code could be written like so:
Still unfortunate that you have to go through
intern/dojo/node
but it works.It’s also in line with the conventions as prescribed in the Intern user guide at https://theintern.github.io/intern/#testing-commonjs-code