Name: js-handler/node_modules/nodeunit/lib/reporters/html.js 
1:
/*!
2:
 * Nodeunit
3:
 * Copyright (c) 2010 Caolan McMahon
4:
 * MIT Licensed
5:
 */
6:
 
7:
/**
8:
 * Module dependencies
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:
 * Reporter info string
19:
 */
20:
 
21:
exports.info = "Report tests result as HTML";
22:
 
23:
/**
24:
 * Run all tests within each module, reporting the results to the command-line.
25:
 *
26:
 * @param {Array} files
27:
 * @api public
28:
 */
29:
 
30:
exports.run = function (files, options, callback) {
31:
 
32:
    var start = new Date().getTime();
33:
    var paths = files.map(function (p) {
34:
        return path.join(process.cwd(), p);
35:
    });
36:
 
37:
    console.log('<html>');
38:
    console.log('<head>');
39:
    console.log('<title></title>');
40:
    console.log('<style type="text/css">');
41:
    console.log('body { font: 12px Helvetica Neue }');
42:
    console.log('h2 { margin:0 ; padding:0 }');
43:
    console.log('pre { font: 11px Andale Mono; margin-left: 1em; padding-left: 1em; margin-top:0; font-size:smaller;}');
44:
    console.log('.assertion_message { margin-left: 1em; }');
45:
    console.log('  ol {' +
46:
    '  list-style: none;' +
47:
    '  margin-left: 1em;' +
48:
    '  padding-left: 1em;' +
49:
    '  text-indent: -1em;' +
50:
    '}');
51:
    console.log('  ol li.pass:before { content: "\\2714 \\0020"; }');
52:
    console.log('  ol li.fail:before { content: "\\2716 \\0020"; }');
53:
    console.log('</style>');
54:
    console.log('</head>');
55:
    console.log('<body>');
56:
    nodeunit.runFiles(paths, {
57:
        testspec: options.testspec,
58:
        testFullSpec: options.testFullSpec,
59:
        moduleStart: function (name) {
60:
            console.log('<h2>' + name + '</h2>');
61:
            console.log('<ol>');
62:
        },
63:
        testDone: function (name, assertions) {
64:
            if (!assertions.failures()) {
65:
                console.log('<li class="pass">' + name + '</li>');
66:
            }
67:
            else {
68:
                console.log('<li class="fail">' + name);
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('<div class="assertion_message">' +
74:
                                'Assertion Message: ' + a.message +
75:
                            '</div>');
76:
                        }
77:
                        console.log('<pre>');
78:
                        console.log(a.error.stack);
79:
                        console.log('</pre>');
80:
                    }
81:
                });
82:
                console.log('</li>');
83:
            }
84:
        },
85:
        moduleDone: function () {
86:
            console.log('</ol>');
87:
        },
88:
        done: function (assertions) {
89:
            var end = new Date().getTime();
90:
            var duration = end - start;
91:
            if (assertions.failures()) {
92:
                console.log(
93:
                    '<h3>FAILURES: '  + assertions.failures() +
94:
                    '/' + assertions.length + ' assertions failed (' +
95:
                    assertions.duration + 'ms)</h3>'
96:
                );
97:
            }
98:
            else {
99:
                console.log(
100:
                    '<h3>OK: ' + assertions.length +
101:
                    ' assertions (' + assertions.duration + 'ms)</h3>'
102:
                );
103:
            }
104:
            console.log('</body>');
105:
            console.log('</html>');
106:
 
107:
            if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
108:
        }
109:
    });
110:
};