UNPKG

1.84 kBJavaScriptView Raw
1/**
2 * Module dependencies
3 */
4
5var nodeunit = require('../nodeunit'),
6 path = require('path'),
7 assert = require('tap').assert,
8 tap = require('tap'),
9 fs = require('fs');
10
11/**
12 * Reporter info string
13 */
14
15exports.info = "TAP output";
16
17/**
18 * Run all tests within each module, reporting the results to the command-line.
19 *
20 * @param {Array} files
21 * @api public
22 */
23
24exports.run = function (files, options, callback) {
25
26 if (!options) {
27 // load default options
28 var content = fs.readFileSync(
29 __dirname + '/../../bin/nodeunit.json', 'utf8'
30 );
31 options = JSON.parse(content);
32 }
33
34 var paths = files.map(function (p) {
35 return path.resolve(p);
36 });
37
38 tap.pipe(process.stdout);
39
40 nodeunit.runFiles(paths, {
41 testStart: function (name) {
42 tap.comment(name.toString());
43 },
44 testDone: function (name, assertions) {
45 assertions.forEach(function (e) {
46 var extra = {};
47 if (e.error) {
48 extra.error = {
49 name: e.error.name,
50 message: e.error.message,
51 stack: e.error.stack.split(/\n/).filter(function (line) {
52 // exclude line of "types.js"
53 return ! RegExp(/types.js:83:39/).test(line);
54 }).join('\n')
55 };
56 extra.wanted = e.error.expected;
57 extra.found = e.error.actual;
58 }
59 tap.assert(e.passed(), e.message, extra);
60 });
61 },
62 done: function (assertions) {
63 tap.end();
64 if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
65 }
66 });
67};