Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nodeunit. #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions lib/_patch/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,72 @@
runner = new JsReporters.JasmineAdapter(jasmine.getEnv());
} else if (window.mocha) {
runner = new JsReporters.MochaAdapter(mocha);
} else if (window.nodeunit) {
console.log('nodeunit adapter');

runner = {
_events: {},
on: function (tag, cb) {
this._events[tag] = cb;
},
emit: function (tag, data) {
if (this._events[tag]) this._events[tag](data);
}
};

var _runModules = nodeunit.runModules;

nodeunit.runModules = function (modules, opt) {
var _opt = {};

for (var k in opt) {
if (Object.prototype.hasOwnProperty.call(opt, k)) {
_opt[k] = opt[k];
}
}

var suites = [], tests = [];

_opt.testDone = function (name, assertions) {
//console.log('_opt.testDone', name, assertions);
var failures = assertions.failures(), errors = [], asserts = [];

for (var i = 0; i < assertions.length; i++) {
var a = assertions[i];

(a.failed() ? errors : asserts).push(new JsReporters.Assertion(
!a.failed(),
'',
'',
a.message || a.method || 'no message',
a.error && a.error.stack ? a.error.stack : undefined
));
}

var test = new JsReporters.Test(name, undefined, [],
failures ? 'failed' : 'passed',
assertions.duration, errors, asserts);

tests.push(test);

//console.log('emit(testEnd)', test);
runner.emit('testEnd', test);

if (opt.testDone) opt.testDone(name, assertions);
}

_opt.done = function (assertions) {
//console.log('_opt.done', assertions);
var suite = new JsReporters.Suite(undefined, [], suites, tests);

//console.log('emit(runEnd)', suite);
runner.emit('runEnd', suite);

opt.done(assertions);
};

return _runModules(modules, _opt);
};
} else {
throw new Error('JsReporters: No testing framework was found');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {

if (pathMatches) {
var framework = config['test_framework'];
var tag_name = (framework === 'mocha') ? 'head' : 'body';
var tag_name = (framework === 'mocha' || framework === 'nodeunit') ? 'head' : 'body';
var patch = '$1';

scripts.forEach(function(script) {
Expand Down Expand Up @@ -196,7 +196,7 @@ exports.Server = function Server(bsClient, workers, config, callback) {
response.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8'
});
var tag_name = (config['test_framework'] === 'mocha') ? 'head' : 'body';
var tag_name = (config['test_framework'] === 'mocha' || config['test_framework'] === 'nodeunit') ? 'head' : 'body';
var matcher = new RegExp('(.*)<\/' + tag_name + '>'); ///(.*)<\/body>/;
var patch = getReporterPatch();
data = data.replace(matcher, patch);
Expand Down