|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var reporters = require('../../').reporters; |
| 4 | +var Doc = reporters.Doc; |
| 5 | + |
| 6 | +describe('Doc reporter', function () { |
| 7 | + var stdout; |
| 8 | + var stdoutWrite; |
| 9 | + var runner = {}; |
| 10 | + beforeEach(function () { |
| 11 | + stdout = []; |
| 12 | + stdoutWrite = process.stdout.write; |
| 13 | + process.stdout.write = function (string) { |
| 14 | + stdout.push(string); |
| 15 | + }; |
| 16 | + }); |
| 17 | + |
| 18 | + describe('on suite', function () { |
| 19 | + describe('if suite root does not exist', function () { |
| 20 | + var expectedTitle = 'expectedTitle'; |
| 21 | + var unescapedTitle = '<div>' + expectedTitle + '</div>'; |
| 22 | + var suite = { |
| 23 | + root: false, |
| 24 | + title: expectedTitle |
| 25 | + }; |
| 26 | + it('should log html with indents and expected title', function () { |
| 27 | + runner.on = function (event, callback) { |
| 28 | + if (event === 'suite') { |
| 29 | + callback(suite); |
| 30 | + } |
| 31 | + }; |
| 32 | + Doc.call(this, runner); |
| 33 | + process.stdout.write = stdoutWrite; |
| 34 | + var expectedArray = [ |
| 35 | + ' <section class="suite">\n', |
| 36 | + ' <h1>' + expectedTitle + '</h1>\n', |
| 37 | + ' <dl>\n' |
| 38 | + ]; |
| 39 | + stdout.should.deepEqual(expectedArray); |
| 40 | + }); |
| 41 | + it('should escape title where necessary', function () { |
| 42 | + var suite = { |
| 43 | + root: false, |
| 44 | + title: unescapedTitle |
| 45 | + }; |
| 46 | + expectedTitle = '<div>' + expectedTitle + '</div>'; |
| 47 | + runner.on = function (event, callback) { |
| 48 | + if (event === 'suite') { |
| 49 | + callback(suite); |
| 50 | + } |
| 51 | + }; |
| 52 | + Doc.call(this, runner); |
| 53 | + process.stdout.write = stdoutWrite; |
| 54 | + var expectedArray = [ |
| 55 | + ' <section class="suite">\n', |
| 56 | + ' <h1>' + expectedTitle + '</h1>\n', |
| 57 | + ' <dl>\n' |
| 58 | + ]; |
| 59 | + stdout.should.deepEqual(expectedArray); |
| 60 | + }); |
| 61 | + }); |
| 62 | + describe('if suite root does exist', function () { |
| 63 | + var suite = { |
| 64 | + root: true |
| 65 | + }; |
| 66 | + it('should not log any html', function () { |
| 67 | + runner.on = function (event, callback) { |
| 68 | + if (event === 'suite') { |
| 69 | + callback(suite); |
| 70 | + } |
| 71 | + }; |
| 72 | + Doc.call(this, runner); |
| 73 | + process.stdout.write = stdoutWrite; |
| 74 | + stdout.should.be.empty(); |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + describe('on suite end', function () { |
| 80 | + describe('if suite root does not exist', function () { |
| 81 | + var suite = { |
| 82 | + root: false |
| 83 | + }; |
| 84 | + it('should log expected html with indents', function () { |
| 85 | + runner.on = function (event, callback) { |
| 86 | + if (event === 'suite end') { |
| 87 | + callback(suite); |
| 88 | + } |
| 89 | + }; |
| 90 | + Doc.call(this, runner); |
| 91 | + process.stdout.write = stdoutWrite; |
| 92 | + var expectedArray = [ |
| 93 | + ' </dl>\n', '</section>\n' |
| 94 | + ]; |
| 95 | + stdout.should.deepEqual(expectedArray); |
| 96 | + }); |
| 97 | + }); |
| 98 | + describe('if suite root does exist', function () { |
| 99 | + var suite = { |
| 100 | + root: true |
| 101 | + }; |
| 102 | + it('should not log any html', function () { |
| 103 | + runner.on = function (event, callback) { |
| 104 | + if (event === 'suite end') { |
| 105 | + callback(suite); |
| 106 | + } |
| 107 | + }; |
| 108 | + Doc.call(this, runner); |
| 109 | + process.stdout.write = stdoutWrite; |
| 110 | + stdout.should.be.empty(); |
| 111 | + }); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + describe('on pass', function () { |
| 116 | + var expectedTitle = 'some tite'; |
| 117 | + var expectedBody = 'some body'; |
| 118 | + var test = { |
| 119 | + title: expectedTitle, |
| 120 | + body: expectedBody, |
| 121 | + slow: function () { |
| 122 | + return ''; |
| 123 | + } |
| 124 | + }; |
| 125 | + it('should log html with indents and expected title and body', function () { |
| 126 | + runner.on = function (event, callback) { |
| 127 | + if (event === 'pass') { |
| 128 | + callback(test); |
| 129 | + } |
| 130 | + }; |
| 131 | + Doc.call(this, runner); |
| 132 | + process.stdout.write = stdoutWrite; |
| 133 | + var expectedArray = [ |
| 134 | + ' <dt>' + expectedTitle + '</dt>\n', |
| 135 | + ' <dd><pre><code>' + expectedBody + '</code></pre></dd>\n' |
| 136 | + ]; |
| 137 | + stdout.should.deepEqual(expectedArray); |
| 138 | + }); |
| 139 | + it('should escape title and body where necessary', function () { |
| 140 | + var unescapedTitle = '<div>' + expectedTitle + '</div>'; |
| 141 | + var unescapedBody = '<div>' + expectedBody + '</div>'; |
| 142 | + test.title = unescapedTitle; |
| 143 | + test.body = unescapedBody; |
| 144 | + |
| 145 | + var expectedEscapedTitle = '<div>' + expectedTitle + '</div>'; |
| 146 | + var expectedEscapedBody = '<div>' + expectedBody + '</div>'; |
| 147 | + runner.on = function (event, callback) { |
| 148 | + if (event === 'pass') { |
| 149 | + callback(test); |
| 150 | + } |
| 151 | + }; |
| 152 | + Doc.call(this, runner); |
| 153 | + process.stdout.write = stdoutWrite; |
| 154 | + var expectedArray = [ |
| 155 | + ' <dt>' + expectedEscapedTitle + '</dt>\n', |
| 156 | + ' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n' |
| 157 | + ]; |
| 158 | + stdout.should.deepEqual(expectedArray); |
| 159 | + }); |
| 160 | + }); |
| 161 | + |
| 162 | + describe('on fail', function () { |
| 163 | + var expectedTitle = 'some tite'; |
| 164 | + var expectedBody = 'some body'; |
| 165 | + var expectedError = 'some error'; |
| 166 | + var test = { |
| 167 | + title: expectedTitle, |
| 168 | + body: expectedBody, |
| 169 | + slow: function () { |
| 170 | + return ''; |
| 171 | + } |
| 172 | + }; |
| 173 | + it('should log html with indents and expected title, body and error', function () { |
| 174 | + runner.on = function (event, callback) { |
| 175 | + if (event === 'fail') { |
| 176 | + callback(test, expectedError); |
| 177 | + } |
| 178 | + }; |
| 179 | + Doc.call(this, runner); |
| 180 | + process.stdout.write = stdoutWrite; |
| 181 | + var expectedArray = [ |
| 182 | + ' <dt class="error">' + expectedTitle + '</dt>\n', |
| 183 | + ' <dd class="error"><pre><code>' + expectedBody + '</code></pre></dd>\n', |
| 184 | + ' <dd class="error">' + expectedError + '</dd>\n' |
| 185 | + ]; |
| 186 | + stdout.should.deepEqual(expectedArray); |
| 187 | + }); |
| 188 | + it('should escape title, body and error where necessary', function () { |
| 189 | + var unescapedTitle = '<div>' + expectedTitle + '</div>'; |
| 190 | + var unescapedBody = '<div>' + expectedBody + '</div>'; |
| 191 | + var unescapedError = '<div>' + expectedError + '</div>'; |
| 192 | + test.title = unescapedTitle; |
| 193 | + test.body = unescapedBody; |
| 194 | + |
| 195 | + var expectedEscapedTitle = '<div>' + expectedTitle + '</div>'; |
| 196 | + var expectedEscapedBody = '<div>' + expectedBody + '</div>'; |
| 197 | + var expectedEscapedError = '<div>' + expectedError + '</div>'; |
| 198 | + runner.on = function (event, callback) { |
| 199 | + if (event === 'fail') { |
| 200 | + callback(test, unescapedError); |
| 201 | + } |
| 202 | + }; |
| 203 | + Doc.call(this, runner); |
| 204 | + process.stdout.write = stdoutWrite; |
| 205 | + var expectedArray = [ |
| 206 | + ' <dt class="error">' + expectedEscapedTitle + '</dt>\n', |
| 207 | + ' <dd class="error"><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n', |
| 208 | + ' <dd class="error">' + expectedEscapedError + '</dd>\n' |
| 209 | + ]; |
| 210 | + stdout.should.deepEqual(expectedArray); |
| 211 | + }); |
| 212 | + }); |
| 213 | +}); |
0 commit comments