Jasmine Spec Runner Generator for JavaScript Unit Tests

Jasmine Spec Runner Generator for JavaScript Unit Tests

Want to automatically generate Test Spec Runner pages for Jasmine's JavaScript Unit tests?

Recently I went through the Atropa Toolbox's javascript classes and functions to write out a comprehensive suite of javascript unit tests. I've been using Jasmine, standalone build, to run my javascript unit tests in the browser.  I got tired of editing the HTML Spec Runner page to add sources and specs every time I wrote a new test. This was something which could be easily automated and integrated into my build process so I didn't have to think about it anymore. So, I created the atropa-jasmine-spec-runner-generator-html as a node module to make it easy to get and use. The module comes with full documentation and files to support visual studio intellisense.

Using my module is really easy, it runs on node so you'll have to have node installed. To get the module just run npm install atropa-jasmine-spec-runner-generator-html and then use it in your build process to generate the HTML spec runner automatically.

// first, require the module.
var JasmineSpecRunnerGenerator = require(
    'atropa-jasmine-spec-runner-generator-html');

// then create an instance, giving jasmineDirectory,
// outputFile, and pageTitle as arguments.
specRunner = new JasmineSpecRunnerGenerator(
    '/js/jasmine/', 'banana tester.html', 'Banana Test Suite');

// addSources generates urls from file names.
// the urls will end up in the src attribute of script tags on
// the generated page. Supply a path to the directory
// containing sources and, a path to the same sources relative
​// to the generated specs page.
specRunner.addSources(__dirname, '/js/myLib/');

// addSpecs also generates urls from file names.
// Supply a path to the directory
// containing specs and, a path to the same specs relative
​// to the generated specs page.
specRunner.addSpecs('./specs/', '/myLib/test/specs/');

// Finally, call the generate or generateFile.

// generate takes a callback function and passes it the
// source of the generated page as a string.
specRunner.generate(console.log);

/*
// generateFile generates the HTML page and saves it to
// the output file. It takes an optional callback function
// which will be called after the output file is generated.
specRunner.generateFile(
    function () {
        console.log('ok');
    }
);
*/
// to reuse this object you can change its
// properties outlined in the documentation.
// change the output file and or page title.
// reset the sourceFiles and specs to empty arrays
// then add sources and specs as shown above.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.