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