1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var nodeunit = require('../nodeunit'),
|
12 | utils = require('../utils'),
|
13 | fs = require('fs'),
|
14 | path = require('path'),
|
15 | AssertionError = require('../assert').AssertionError;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | exports.info = "Skip passed tests output";
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | exports.run = function (files, options, callback) {
|
31 |
|
32 | if (!options) {
|
33 |
|
34 | var content = fs.readFileSync(
|
35 | __dirname + '/../../bin/nodeunit.json', 'utf8'
|
36 | );
|
37 | options = JSON.parse(content);
|
38 | }
|
39 |
|
40 | var error = function (str) {
|
41 | return options.error_prefix + str + options.error_suffix;
|
42 | };
|
43 | var ok = function (str) {
|
44 | return options.ok_prefix + str + options.ok_suffix;
|
45 | };
|
46 | var bold = function (str) {
|
47 | return options.bold_prefix + str + options.bold_suffix;
|
48 | };
|
49 | var assertion_message = function (str) {
|
50 | return options.assertion_prefix + str + options.assertion_suffix;
|
51 | };
|
52 | var pass_indicator = process.platform === 'win32' ? '\u221A' : '✔';
|
53 | var fail_indicator = process.platform === 'win32' ? '\u00D7' : '✖';
|
54 |
|
55 | var start = new Date().getTime();
|
56 | var paths = files.map(function (p) {
|
57 | return path.resolve(p);
|
58 | });
|
59 |
|
60 | nodeunit.runFiles(paths, {
|
61 | testspec: options.testspec,
|
62 | testFullSpec: options.testFullSpec,
|
63 | moduleStart: function (name) {
|
64 | console.log('\n' + bold(name));
|
65 | },
|
66 | testDone: function (name, assertions) {
|
67 | if (assertions.failures()) {
|
68 | console.log(error(fail_indicator + ' ' + name) + '\n');
|
69 | assertions.forEach(function (a) {
|
70 | if (a.failed()) {
|
71 | a = utils.betterErrors(a);
|
72 | if (a.error instanceof AssertionError && a.message) {
|
73 | console.log(
|
74 | 'Assertion Message: ' + assertion_message(a.message)
|
75 | );
|
76 | }
|
77 | console.log(a.error.stack + '\n');
|
78 | }
|
79 | });
|
80 | }
|
81 | },
|
82 | moduleDone: function (name, assertions) {
|
83 | if (!assertions.failures()) {
|
84 | console.log(pass_indicator + ' all tests passed');
|
85 | }
|
86 | else {
|
87 | console.log(error(fail_indicator + ' some tests failed'));
|
88 | }
|
89 | },
|
90 | done: function (assertions) {
|
91 | var end = new Date().getTime();
|
92 | var duration = end - start;
|
93 | if (assertions.failures()) {
|
94 | console.log(
|
95 | '\n' + bold(error('FAILURES: ')) + assertions.failures() +
|
96 | '/' + assertions.length + ' assertions failed (' +
|
97 | assertions.duration + 'ms)'
|
98 | );
|
99 | }
|
100 | else {
|
101 | console.log(
|
102 | '\n' + bold(ok('OK: ')) + assertions.length +
|
103 | ' assertions (' + assertions.duration + 'ms)'
|
104 | );
|
105 | }
|
106 |
|
107 | if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
|
108 | }
|
109 | });
|
110 | };
|