|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var reporters = require('../../').reporters; |
| 4 | +var List = reporters.List; |
| 5 | +var Base = reporters.Base; |
| 6 | + |
| 7 | +describe('List reporter', function () { |
| 8 | + var stdout; |
| 9 | + var stdoutWrite; |
| 10 | + var runner; |
| 11 | + var useColors; |
| 12 | + |
| 13 | + beforeEach(function () { |
| 14 | + stdout = []; |
| 15 | + runner = {}; |
| 16 | + stdoutWrite = process.stdout.write; |
| 17 | + process.stdout.write = function (string) { |
| 18 | + stdout.push(string); |
| 19 | + }; |
| 20 | + useColors = Base.useColors; |
| 21 | + Base.useColors = false; |
| 22 | + }); |
| 23 | + |
| 24 | + afterEach(function () { |
| 25 | + Base.useColors = useColors; |
| 26 | + }); |
| 27 | + |
| 28 | + describe('on start and test', function () { |
| 29 | + it('should write expected new line and title to the console', function () { |
| 30 | + var expectedTitle = 'some title'; |
| 31 | + var test = { |
| 32 | + fullTitle: function () { |
| 33 | + return expectedTitle; |
| 34 | + } |
| 35 | + }; |
| 36 | + runner.on = function (event, callback) { |
| 37 | + if (event === 'start') { |
| 38 | + callback(); |
| 39 | + } |
| 40 | + if (event === 'test') { |
| 41 | + callback(test); |
| 42 | + } |
| 43 | + }; |
| 44 | + List.call({epilogue: function () {}}, runner); |
| 45 | + |
| 46 | + process.stdout.write = stdoutWrite; |
| 47 | + var startString = '\n'; |
| 48 | + var testString = ' ' + expectedTitle + ': '; |
| 49 | + var expectedArray = [ |
| 50 | + startString, |
| 51 | + testString |
| 52 | + ]; |
| 53 | + stdout.should.deepEqual(expectedArray); |
| 54 | + }); |
| 55 | + }); |
| 56 | + describe('on pending', function () { |
| 57 | + it('should write expected title to the console', function () { |
| 58 | + var expectedTitle = 'some title'; |
| 59 | + var test = { |
| 60 | + fullTitle: function () { |
| 61 | + return expectedTitle; |
| 62 | + } |
| 63 | + }; |
| 64 | + runner.on = function (event, callback) { |
| 65 | + if (event === 'pending') { |
| 66 | + callback(test); |
| 67 | + } |
| 68 | + }; |
| 69 | + List.call({epilogue: function () {}}, runner); |
| 70 | + |
| 71 | + process.stdout.write = stdoutWrite; |
| 72 | + |
| 73 | + stdout[0].should.deepEqual(' - ' + expectedTitle + '\n'); |
| 74 | + }); |
| 75 | + }); |
| 76 | + describe('on pass', function () { |
| 77 | + it('should call cursor CR', function () { |
| 78 | + var calledCursorCR = false; |
| 79 | + var cachedCursor = Base.cursor; |
| 80 | + Base.cursor.CR = function () { |
| 81 | + calledCursorCR = true; |
| 82 | + }; |
| 83 | + var expectedTitle = 'some title'; |
| 84 | + var expectedDuration = 100; |
| 85 | + var test = { |
| 86 | + fullTitle: function () { |
| 87 | + return expectedTitle; |
| 88 | + }, |
| 89 | + duration: expectedDuration, |
| 90 | + slow: function () {} |
| 91 | + }; |
| 92 | + runner.on = function (event, callback) { |
| 93 | + if (event === 'pass') { |
| 94 | + callback(test); |
| 95 | + } |
| 96 | + }; |
| 97 | + List.call({epilogue: function () {}}, runner); |
| 98 | + |
| 99 | + process.stdout.write = stdoutWrite; |
| 100 | + |
| 101 | + calledCursorCR.should.be.true(); |
| 102 | + |
| 103 | + Base.cursor = cachedCursor; |
| 104 | + }); |
| 105 | + it('should write expected symbol, title and duration to the console', function () { |
| 106 | + var cachedSymbols = Base.symbols; |
| 107 | + var expectedOkSymbol = 'OK'; |
| 108 | + Base.symbols.ok = expectedOkSymbol; |
| 109 | + var cachedCursor = Base.cursor; |
| 110 | + Base.cursor.CR = function () {}; |
| 111 | + var expectedTitle = 'some title'; |
| 112 | + var expectedDuration = 100; |
| 113 | + var test = { |
| 114 | + fullTitle: function () { |
| 115 | + return expectedTitle; |
| 116 | + }, |
| 117 | + duration: expectedDuration, |
| 118 | + slow: function () {} |
| 119 | + }; |
| 120 | + runner.on = function (event, callback) { |
| 121 | + if (event === 'pass') { |
| 122 | + callback(test); |
| 123 | + } |
| 124 | + }; |
| 125 | + List.call({epilogue: function () {}}, runner); |
| 126 | + |
| 127 | + process.stdout.write = stdoutWrite; |
| 128 | + |
| 129 | + stdout[0].should.equal(' ' + expectedOkSymbol + ' ' + expectedTitle + ': ' + expectedDuration + 'ms\n'); |
| 130 | + |
| 131 | + Base.cursor = cachedCursor; |
| 132 | + Base.symbols = cachedSymbols; |
| 133 | + }); |
| 134 | + }); |
| 135 | + describe('on fail', function () { |
| 136 | + it('should call cursor CR', function () { |
| 137 | + var calledCursorCR = false; |
| 138 | + var cachedCursor = Base.cursor; |
| 139 | + Base.cursor.CR = function () { |
| 140 | + calledCursorCR = true; |
| 141 | + }; |
| 142 | + var expectedTitle = 'some title'; |
| 143 | + var expectedDuration = 100; |
| 144 | + var test = { |
| 145 | + fullTitle: function () { |
| 146 | + return expectedTitle; |
| 147 | + }, |
| 148 | + duration: expectedDuration, |
| 149 | + slow: function () {} |
| 150 | + }; |
| 151 | + runner.on = function (event, callback) { |
| 152 | + if (event === 'fail') { |
| 153 | + callback(test); |
| 154 | + } |
| 155 | + }; |
| 156 | + List.call({epilogue: function () {}}, runner); |
| 157 | + |
| 158 | + process.stdout.write = stdoutWrite; |
| 159 | + |
| 160 | + calledCursorCR.should.be.true(); |
| 161 | + |
| 162 | + Base.cursor = cachedCursor; |
| 163 | + }); |
| 164 | + it('should write expected error number and title', function () { |
| 165 | + var cachedCursor = Base.cursor; |
| 166 | + var expectedErrorCount = 1; |
| 167 | + Base.cursor.CR = function () {}; |
| 168 | + var expectedTitle = 'some title'; |
| 169 | + var expectedDuration = 100; |
| 170 | + var test = { |
| 171 | + fullTitle: function () { |
| 172 | + return expectedTitle; |
| 173 | + }, |
| 174 | + duration: expectedDuration, |
| 175 | + slow: function () {} |
| 176 | + }; |
| 177 | + runner.on = function (event, callback) { |
| 178 | + if (event === 'fail') { |
| 179 | + callback(test); |
| 180 | + } |
| 181 | + }; |
| 182 | + runner.on = function (event, callback) { |
| 183 | + if (event === 'fail') { |
| 184 | + callback(test); |
| 185 | + } |
| 186 | + }; |
| 187 | + List.call({epilogue: function () {}}, runner); |
| 188 | + |
| 189 | + process.stdout.write = stdoutWrite; |
| 190 | + |
| 191 | + stdout[0].should.equal(' ' + expectedErrorCount + ') ' + expectedTitle + '\n'); |
| 192 | + |
| 193 | + Base.cursor = cachedCursor; |
| 194 | + }); |
| 195 | + }); |
| 196 | + |
| 197 | + describe('on end', function () { |
| 198 | + it('should call epilogue', function () { |
| 199 | + var calledEpilogue = false; |
| 200 | + runner.on = function (event, callback) { |
| 201 | + if (event === 'end') { |
| 202 | + callback(); |
| 203 | + } |
| 204 | + }; |
| 205 | + List.call({ |
| 206 | + epilogue: function () { |
| 207 | + calledEpilogue = true; |
| 208 | + } |
| 209 | + }, runner); |
| 210 | + process.stdout.write = stdoutWrite; |
| 211 | + |
| 212 | + calledEpilogue.should.be.true(); |
| 213 | + }); |
| 214 | + }); |
| 215 | +}); |
0 commit comments