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!
![5 Ways that CSS and JavaScript Interact That You May Not Know About]()
CSS and JavaScript: the lines seemingly get blurred by each browser release. They have always done a very different job but in the end they are both front-end technologies so they need do need to work closely. We have our .js files and our .css, but...
![Create a CSS Flipping Animation]()
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
![Fancy FAQs with MooTools Sliders: Version 2]()
A little over a year ago I authored a post titled Fancy FAQs with MooTools Sliders. My post detailed a method of taking boring FAQs and making them more robust using the world's best JavaScript framework: MooTools. I've taken some time to...
![Create a Spinning, Zooming Effect with CSS3]()
In case you weren't aware, CSS animations are awesome. They're smooth, less taxing than JavaScript, and are the future of node animation within browsers. Dojo's mobile solution, dojox.mobile
, uses CSS animations instead of JavaScript to lighten the application's JavaScript footprint. One of my favorite effects...
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