stupa

1.0.7 • Public • Published

stupa

A javascript test runner that running jasmine on node

Usage

Stupa is a javascript test runner that help your to run your jasmine specs in node way.

First, install stupa to the global env.

npm install -g stupa

Then, generating the config file.

stupa init

This command will generate a configure file named stupa.conf.js in the currently directory.

stupa.conf.js

module.exports = {
    // Time to wait in milliseconds before a test automatically fails.
    timeout: 5000,
 
    specs: {
        // A prefix for all spec_files and helpers
        spec_dir: './',
        // The paths of the spec files
        spec_files: [ 'app/spec/*.js' ],
        // The paths of the spec helpers
        helpers: [ 'app/specHelpers/*.js' ]
    },
 
    /* A collection of javascript jasmine reporter classes
        - Included reporters:
            AppVeyorReporter - POSTs results to AppVeyor when running inside an AppVeyor environment.
            JUnitXmlReporter - Report test results to a file in JUnit XML Report format.
            NUnitXmlReporter - Report test results to a file in NUnit XML Report format.
            TapReporter - Test Anything Protocol, report tests results to console.
            TeamCityReporter - Basic reporter that outputs spec results to for the Teamcity build system.
            TerminalReporter - Logs to a terminal (including colors) with variable verbosity.
        eg:
            reporters: [ 'TapReporter', 'JUnitXmlReporter' ]
        It will set to a terminal reporter if left it empty.
    */
    reporters: [  ]
}

Of course , you can write the config file by hand or copy paste it from another project.

Finally, starting stupa.

stupa start

When starting Stupa, the configuration file path can be passed in as the first argument.

By default, Stupa will look for stupa.conf.js in the current directory.

Of course, you could specify the configurion file by running:

stupa start mySpec.conf.js

Command line arguments

Specify the running file by using --file=path/to/your/spec/file, it will overwrite the spec files config

stupa start mySpec.conf.js --file=app/spec/my.spec.js

--stop-on-failure=true/false stops execution of a spec after the first expectation failure when set to true

stupa start mySpec.conf.js --file=app/spec/my.spec.js --stop-on-failure=true

Bast practice

Using with phantom to make a suite of end to end test case.
And, use superagent to test the RESTFUL APIS.

example.spec.js

var phantom = require('phantom');
var agent = require('superagent')
var http = require('http');
 
describe('A suite of end to end test case - ', function () {
    var server;
 
    beforeAll(function (done) {
        server = http.createServer(function (req, res) {
            if (req.url === '/html') {
                res.end('<html><head><title>Stupa!</title></head><body>Hello Stupa.</body></html>');
            } else if ('/json') {
                res.writeHead(200, { 'Content-Type': 'application/json' });
                res.end(JSON.stringify({ data: 'hello stupa!' }));
            } else {
                res.end('hi, ' + req.url);
            }
        });
        server.listen(7777, done);
    });
    afterAll(function () {
        server.close();
    });
 
    it('page should be successfully opened', function (done) {
        phantom.create().then(function (ph) {
            ph.createPage().then(function (page) {
                page.open('http://localhost:7777/html').then(function (status) {
                    page.evaluate(function () {
                        return document.title;
                    }).then(function (title) {
                        expect(status).toEqual('success');
                        expect(title).toEqual('Stupa!');
                        done();
                        ph.exit();
                    })
                })
            })
        })
    });
    it('asynchronous data should be successfully response', function (done) {
        agent.get('http://localhost:7777/json').end(function (err, res) {
            expect(res.statusCode).toEqual(200);
            expect(res.body.data).toEqual('hello stupa!');
            done();
        })
    });
})

Run:

cd to/the/path/of/example.spec.js
npm install -g stupa
npm install phantom@latest superagent@latest
stupa init
stupa start --file=example.spec.js

Package Sidebar

Install

npm i stupa

Weekly Downloads

1

Version

1.0.7

License

ISC

Last publish

Collaborators

  • jacketchen