1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var Base = require('./base');
|
10 | var utils = require('../utils');
|
11 | var constants = require('../runner').constants;
|
12 | var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
13 | var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
14 | var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
15 | var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | exports = module.exports = Doc;
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function Doc(runner, options) {
|
34 | Base.call(this, runner, options);
|
35 |
|
36 | var indents = 2;
|
37 |
|
38 | function indent() {
|
39 | return Array(indents).join(' ');
|
40 | }
|
41 |
|
42 | runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
43 | if (suite.root) {
|
44 | return;
|
45 | }
|
46 | ++indents;
|
47 | Base.consoleLog('%s<section class="suite">', indent());
|
48 | ++indents;
|
49 | Base.consoleLog('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
|
50 | Base.consoleLog('%s<dl>', indent());
|
51 | });
|
52 |
|
53 | runner.on(EVENT_SUITE_END, function(suite) {
|
54 | if (suite.root) {
|
55 | return;
|
56 | }
|
57 | Base.consoleLog('%s</dl>', indent());
|
58 | --indents;
|
59 | Base.consoleLog('%s</section>', indent());
|
60 | --indents;
|
61 | });
|
62 |
|
63 | runner.on(EVENT_TEST_PASS, function(test) {
|
64 | Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.title));
|
65 | var code = utils.escape(utils.clean(test.body));
|
66 | Base.consoleLog('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
|
67 | });
|
68 |
|
69 | runner.on(EVENT_TEST_FAIL, function(test, err) {
|
70 | Base.consoleLog(
|
71 | '%s <dt class="error">%s</dt>',
|
72 | indent(),
|
73 | utils.escape(test.title)
|
74 | );
|
75 | var code = utils.escape(utils.clean(test.body));
|
76 | Base.consoleLog(
|
77 | '%s <dd class="error"><pre><code>%s</code></pre></dd>',
|
78 | indent(),
|
79 | code
|
80 | );
|
81 | Base.consoleLog(
|
82 | '%s <dd class="error">%s</dd>',
|
83 | indent(),
|
84 | utils.escape(err)
|
85 | );
|
86 | });
|
87 | }
|
88 |
|
89 | Doc.description = 'HTML documentation';
|