-
-
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.
test(test/reporters): Rework reporter tests
Reworked stubs to use sinon. Added logic to (hopefully) rethrow errors when stdout stubbed. Now uses event constants. Noise reduction. Various mods for consistency. Now green across the board.
- Loading branch information
Showing
15 changed files
with
2,528 additions
and
1,793 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,189 +1,241 @@ | ||
'use strict'; | ||
|
||
var events = require('../../').Runner.constants; | ||
var helpers = require('./helpers'); | ||
var reporters = require('../../').reporters; | ||
|
||
var Doc = reporters.Doc; | ||
var createMockRunner = helpers.createMockRunner; | ||
var makeRunReporter = helpers.createRunReporterFunction; | ||
|
||
var createMockRunner = require('./helpers.js').createMockRunner; | ||
var makeRunReporter = require('./helpers.js').createRunReporterFunction; | ||
var EVENT_SUITE_BEGIN = events.EVENT_SUITE_BEGIN; | ||
var EVENT_SUITE_END = events.EVENT_SUITE_END; | ||
var EVENT_TEST_FAIL = events.EVENT_TEST_FAIL; | ||
var EVENT_TEST_PASS = events.EVENT_TEST_PASS; | ||
|
||
describe('Doc reporter', function() { | ||
var runner; | ||
var options = {}; | ||
var runReporter = makeRunReporter(Doc); | ||
|
||
afterEach(function() { | ||
runner = undefined; | ||
runner = null; | ||
}); | ||
|
||
describe('on suite', function() { | ||
describe('if suite root does not exist', function() { | ||
var expectedTitle = 'expectedTitle'; | ||
var unescapedTitle = '<div>' + expectedTitle + '</div>'; | ||
var suite = { | ||
root: false, | ||
title: expectedTitle | ||
describe('event handlers', function() { | ||
describe("on 'suite' event", function() { | ||
describe('when suite root does not exist', function() { | ||
var expectedTitle = 'expectedTitle'; | ||
var unescapedTitle = '<div>' + expectedTitle + '</div>'; | ||
var suite = { | ||
root: false, | ||
title: expectedTitle | ||
}; | ||
|
||
it('should log html with indents and expected title', function() { | ||
runner = createMockRunner( | ||
'suite', | ||
EVENT_SUITE_BEGIN, | ||
null, | ||
null, | ||
suite | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <section class="suite">\n', | ||
' <h1>' + expectedTitle + '</h1>\n', | ||
' <dl>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
|
||
it('should escape title where necessary', function() { | ||
var suite = { | ||
root: false, | ||
title: unescapedTitle | ||
}; | ||
expectedTitle = | ||
'<div>' + expectedTitle + '</div>'; | ||
|
||
runner = createMockRunner( | ||
'suite', | ||
EVENT_SUITE_BEGIN, | ||
null, | ||
null, | ||
suite | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <section class="suite">\n', | ||
' <h1>' + expectedTitle + '</h1>\n', | ||
' <dl>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
|
||
describe('when suite root exists', function() { | ||
var suite = { | ||
root: true | ||
}; | ||
|
||
it('should not log any html', function() { | ||
runner = createMockRunner( | ||
'suite', | ||
EVENT_SUITE_BEGIN, | ||
null, | ||
null, | ||
suite | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
expect(stdout, 'to be empty'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("on 'suite end' event", function() { | ||
describe('when suite root does not exist', function() { | ||
var suite = { | ||
root: false | ||
}; | ||
|
||
it('should log expected html with indents', function() { | ||
runner = createMockRunner( | ||
'suite end', | ||
EVENT_SUITE_END, | ||
null, | ||
null, | ||
suite | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [' </dl>\n', '</section>\n']; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
|
||
describe('when suite root exists', function() { | ||
var suite = { | ||
root: true | ||
}; | ||
|
||
it('should not log any html', function() { | ||
runner = createMockRunner( | ||
'suite end', | ||
EVENT_SUITE_END, | ||
null, | ||
null, | ||
suite | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
expect(stdout, 'to be empty'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("on 'pass' event", function() { | ||
var expectedTitle = 'some tite'; | ||
var expectedBody = 'some body'; | ||
var test = { | ||
title: expectedTitle, | ||
body: expectedBody, | ||
slow: function() { | ||
return ''; | ||
} | ||
}; | ||
it('should log html with indents and expected title', function() { | ||
runner = createMockRunner('suite', 'suite', null, null, suite); | ||
|
||
it('should log html with indents, expected title, and body', function() { | ||
runner = createMockRunner('pass', EVENT_TEST_PASS, null, null, test); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <section class="suite">\n', | ||
' <h1>' + expectedTitle + '</h1>\n', | ||
' <dl>\n' | ||
' <dt>' + expectedTitle + '</dt>\n', | ||
' <dd><pre><code>' + expectedBody + '</code></pre></dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
it('should escape title where necessary', function() { | ||
var suite = { | ||
root: false, | ||
title: unescapedTitle | ||
}; | ||
expectedTitle = '<div>' + expectedTitle + '</div>'; | ||
runner = createMockRunner('suite', 'suite', null, null, suite); | ||
|
||
it('should escape title and body where necessary', function() { | ||
var unescapedTitle = '<div>' + expectedTitle + '</div>'; | ||
var unescapedBody = '<div>' + expectedBody + '</div>'; | ||
test.title = unescapedTitle; | ||
test.body = unescapedBody; | ||
|
||
var expectedEscapedTitle = | ||
'<div>' + expectedTitle + '</div>'; | ||
var expectedEscapedBody = | ||
'<div>' + expectedBody + '</div>'; | ||
runner = createMockRunner('pass', EVENT_TEST_PASS, null, null, test); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <section class="suite">\n', | ||
' <h1>' + expectedTitle + '</h1>\n', | ||
' <dl>\n' | ||
' <dt>' + expectedEscapedTitle + '</dt>\n', | ||
' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
describe('if suite root does exist', function() { | ||
var suite = { | ||
root: true | ||
}; | ||
it('should not log any html', function() { | ||
runner = createMockRunner('suite', 'suite', null, null, suite); | ||
var stdout = runReporter(this, runner, options); | ||
expect(stdout, 'to be empty'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('on suite end', function() { | ||
describe('if suite root does not exist', function() { | ||
var suite = { | ||
root: false | ||
describe("on 'fail' event", function() { | ||
var expectedTitle = 'some tite'; | ||
var expectedBody = 'some body'; | ||
var expectedError = 'some error'; | ||
var test = { | ||
title: expectedTitle, | ||
body: expectedBody, | ||
slow: function() { | ||
return ''; | ||
} | ||
}; | ||
it('should log expected html with indents', function() { | ||
runner = createMockRunner('suite end', 'suite end', null, null, suite); | ||
|
||
it('should log html with indents, expected title, body, and error', function() { | ||
runner = createMockRunner( | ||
'fail two args', | ||
EVENT_TEST_FAIL, | ||
null, | ||
null, | ||
test, | ||
expectedError | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [' </dl>\n', '</section>\n']; | ||
var expectedArray = [ | ||
' <dt class="error">' + expectedTitle + '</dt>\n', | ||
' <dd class="error"><pre><code>' + | ||
expectedBody + | ||
'</code></pre></dd>\n', | ||
' <dd class="error">' + expectedError + '</dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
describe('if suite root does exist', function() { | ||
var suite = { | ||
root: true | ||
}; | ||
it('should not log any html', function() { | ||
runner = createMockRunner('suite end', 'suite end', null, null, suite); | ||
var stdout = runReporter(this, runner, options); | ||
expect(stdout, 'to be empty'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('on pass', function() { | ||
var expectedTitle = 'some tite'; | ||
var expectedBody = 'some body'; | ||
var test = { | ||
title: expectedTitle, | ||
body: expectedBody, | ||
slow: function() { | ||
return ''; | ||
} | ||
}; | ||
it('should log html with indents and expected title and body', function() { | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <dt>' + expectedTitle + '</dt>\n', | ||
' <dd><pre><code>' + expectedBody + '</code></pre></dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
it('should escape title and body where necessary', function() { | ||
var unescapedTitle = '<div>' + expectedTitle + '</div>'; | ||
var unescapedBody = '<div>' + expectedBody + '</div>'; | ||
test.title = unescapedTitle; | ||
test.body = unescapedBody; | ||
|
||
var expectedEscapedTitle = | ||
'<div>' + expectedTitle + '</div>'; | ||
var expectedEscapedBody = | ||
'<div>' + expectedBody + '</div>'; | ||
runner = createMockRunner('pass', 'pass', null, null, test); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <dt>' + expectedEscapedTitle + '</dt>\n', | ||
' <dd><pre><code>' + expectedEscapedBody + '</code></pre></dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
it('should escape title, body, and error where necessary', function() { | ||
var unescapedTitle = '<div>' + expectedTitle + '</div>'; | ||
var unescapedBody = '<div>' + expectedBody + '</div>'; | ||
var unescapedError = '<div>' + expectedError + '</div>'; | ||
test.title = unescapedTitle; | ||
test.body = unescapedBody; | ||
|
||
describe('on fail', function() { | ||
var expectedTitle = 'some tite'; | ||
var expectedBody = 'some body'; | ||
var expectedError = 'some error'; | ||
var test = { | ||
title: expectedTitle, | ||
body: expectedBody, | ||
slow: function() { | ||
return ''; | ||
} | ||
}; | ||
it('should log html with indents and expected title, body and error', function() { | ||
runner = createMockRunner( | ||
'fail two args', | ||
'fail', | ||
null, | ||
null, | ||
test, | ||
expectedError | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <dt class="error">' + expectedTitle + '</dt>\n', | ||
' <dd class="error"><pre><code>' + | ||
expectedBody + | ||
'</code></pre></dd>\n', | ||
' <dd class="error">' + expectedError + '</dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
it('should escape title, body and error where necessary', function() { | ||
var unescapedTitle = '<div>' + expectedTitle + '</div>'; | ||
var unescapedBody = '<div>' + expectedBody + '</div>'; | ||
var unescapedError = '<div>' + expectedError + '</div>'; | ||
test.title = unescapedTitle; | ||
test.body = unescapedBody; | ||
|
||
var expectedEscapedTitle = | ||
'<div>' + expectedTitle + '</div>'; | ||
var expectedEscapedBody = | ||
'<div>' + expectedBody + '</div>'; | ||
var expectedEscapedError = | ||
'<div>' + expectedError + '</div>'; | ||
runner = createMockRunner( | ||
'fail two args', | ||
'fail', | ||
null, | ||
null, | ||
test, | ||
unescapedError | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <dt class="error">' + expectedEscapedTitle + '</dt>\n', | ||
' <dd class="error"><pre><code>' + | ||
expectedEscapedBody + | ||
'</code></pre></dd>\n', | ||
' <dd class="error">' + expectedEscapedError + '</dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
var expectedEscapedTitle = | ||
'<div>' + expectedTitle + '</div>'; | ||
var expectedEscapedBody = | ||
'<div>' + expectedBody + '</div>'; | ||
var expectedEscapedError = | ||
'<div>' + expectedError + '</div>'; | ||
runner = createMockRunner( | ||
'fail two args', | ||
EVENT_TEST_FAIL, | ||
null, | ||
null, | ||
test, | ||
unescapedError | ||
); | ||
var stdout = runReporter(this, runner, options); | ||
var expectedArray = [ | ||
' <dt class="error">' + expectedEscapedTitle + '</dt>\n', | ||
' <dd class="error"><pre><code>' + | ||
expectedEscapedBody + | ||
'</code></pre></dd>\n', | ||
' <dd class="error">' + expectedEscapedError + '</dd>\n' | ||
]; | ||
expect(stdout, 'to equal', expectedArray); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.