-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
'use strict'; | ||
|
||
var reporters = require('../../').reporters; | ||
var Landing = reporters.Landing; | ||
var Base = reporters.Base; | ||
|
||
describe('Landing reporter', function () { | ||
var stdout; | ||
var stdoutWrite; | ||
var runner; | ||
var useColors; | ||
var windowWidth; | ||
|
||
beforeEach(function () { | ||
stdout = []; | ||
runner = {}; | ||
stdoutWrite = process.stdout.write; | ||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
useColors = Base.useColors; | ||
Base.useColors = false; | ||
windowWidth = Base.window.width; | ||
Base.window.width = 1; | ||
}); | ||
|
||
afterEach(function () { | ||
Base.useColors = useColors; | ||
Base.window.width = windowWidth; | ||
}); | ||
|
||
describe('on start', function () { | ||
it('should write new lines', function () { | ||
var cachedCursor = Base.cursor; | ||
Base.cursor.hide = function () {}; | ||
runner.on = function (event, callback) { | ||
if (event === 'start') { | ||
callback(); | ||
} | ||
}; | ||
Landing.call({}, runner); | ||
|
||
process.stdout.write = stdoutWrite; | ||
|
||
stdout[0].should.deepEqual('\n\n\n '); | ||
Base.cursor = cachedCursor; | ||
}); | ||
|
||
it('should call cursor hide', function () { | ||
var cachedCursor = Base.cursor; | ||
var calledCursorHide = false; | ||
Base.cursor.hide = function () { | ||
calledCursorHide = true; | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'start') { | ||
callback(); | ||
} | ||
}; | ||
Landing.call({}, runner); | ||
|
||
process.stdout.write = stdoutWrite; | ||
calledCursorHide.should.be.true(); | ||
|
||
Base.cursor = cachedCursor; | ||
}); | ||
}); | ||
|
||
describe('on test end', function () { | ||
describe('if test has failed', function () { | ||
it('should write expected landing strip', function () { | ||
var test = { | ||
state: 'failed' | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'test end') { | ||
callback(test); | ||
} | ||
}; | ||
runner.total = 12; | ||
Landing.call({}, runner); | ||
|
||
process.stdout.write = stdoutWrite; | ||
|
||
var expectedArray = [ '\u001b[1D\u001b[2A', | ||
' ', | ||
'\n ', | ||
'', | ||
'✈', | ||
'\n', | ||
' ', | ||
'\u001b[0m' | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
describe('if test has not failed', function () { | ||
it('should write expected landing strip', function () { | ||
var test = { | ||
state: 'success' | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'test end') { | ||
callback(test); | ||
} | ||
}; | ||
|
||
Landing.call({}, runner); | ||
|
||
process.stdout.write = stdoutWrite; | ||
|
||
var expectedArray = [ '\u001b[1D\u001b[2A', | ||
' ', | ||
'\n ', | ||
'', | ||
'✈', | ||
'\n', | ||
' ', | ||
'\u001b[0m' | ||
]; | ||
stdout.should.deepEqual(expectedArray); | ||
}); | ||
}); | ||
}); | ||
describe('on end', function () { | ||
it('should call cursor show and epilogue', function () { | ||
var cachedCursor = Base.cursor; | ||
var calledCursorShow = false; | ||
Base.cursor.show = function () { | ||
calledCursorShow = true; | ||
}; | ||
runner.on = function (event, callback) { | ||
if (event === 'end') { | ||
callback(); | ||
} | ||
}; | ||
var calledEpilogue = false; | ||
Landing.call({ | ||
epilogue: function () { | ||
calledEpilogue = true; | ||
} | ||
}, runner); | ||
|
||
process.stdout.write = stdoutWrite; | ||
calledEpilogue.should.be.true(); | ||
calledCursorShow.should.be.true(); | ||
|
||
Base.cursor = cachedCursor; | ||
}); | ||
}); | ||
}); |