-
-
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.
Merge pull request #1631 from mantoni/fix-safari-consolify
fix(reporter/base): don't assume error message is first line of stack
- Loading branch information
Showing
2 changed files
with
96 additions
and
87 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
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,153 +1,155 @@ | ||
var Base = require('../../lib/reporters/base') | ||
, Assert = require('assert').AssertionError; | ||
|
||
function makeTest(err) { | ||
return { | ||
err: err, | ||
fullTitle: function () { | ||
return 'test title'; | ||
} | ||
}; | ||
} | ||
|
||
describe('Base reporter', function () { | ||
var stdout | ||
, stdoutWrite | ||
, useColors; | ||
|
||
beforeEach(function () { | ||
stdout = []; | ||
stdoutWrite = process.stdout.write; | ||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
useColors = Base.useColors; | ||
Base.useColors = false; | ||
}); | ||
|
||
afterEach(function () { | ||
process.stdout.write = stdoutWrite; | ||
Base.useColors = useColors; | ||
}); | ||
|
||
describe('showDiff', function() { | ||
it('should show diffs by default', function () { | ||
var err = new Assert({ actual: 'foo', expected: 'bar' }) | ||
, stdout = [] | ||
, stdoutWrite = process.stdout.write | ||
, errOut; | ||
|
||
var test = { | ||
err: err, | ||
fullTitle: function () { | ||
return 'test title'; | ||
} | ||
}; | ||
|
||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
var test = makeTest(err); | ||
|
||
Base.list([test]); | ||
|
||
process.stdout.write = stdoutWrite; | ||
|
||
errOut = stdout.join('\n'); | ||
errOut.should.match(/actual/); | ||
errOut.should.match(/expected/); | ||
errOut.should.match(/\- actual/); | ||
errOut.should.match(/\+ expected/); | ||
}); | ||
|
||
it('should show diffs if property set to `true`', function () { | ||
var err = new Assert({ actual: 'foo', expected: 'bar' }) | ||
, stdout = [] | ||
, stdoutWrite = process.stdout.write | ||
, errOut; | ||
|
||
err.showDiff = true; | ||
var test = { | ||
err: err, | ||
fullTitle: function () { | ||
return 'test title'; | ||
} | ||
}; | ||
var test = makeTest(err); | ||
|
||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
|
||
Base.list([test]); | ||
|
||
process.stdout.write = stdoutWrite; | ||
|
||
errOut = stdout.join('\n'); | ||
errOut.should.match(/actual/); | ||
errOut.should.match(/expected/); | ||
errOut.should.match(/\- actual/); | ||
errOut.should.match(/\+ expected/); | ||
}); | ||
|
||
it('should not show diffs when showDiff property set to `false`', function () { | ||
var err = new Assert({ actual: 'foo', expected: 'bar' }) | ||
, stdout = [] | ||
, stdoutWrite = process.stdout.write | ||
, errOut; | ||
|
||
err.showDiff = false; | ||
var test = { | ||
err: err, | ||
fullTitle: function () { | ||
return 'test title'; | ||
} | ||
}; | ||
|
||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
var test = makeTest(err); | ||
|
||
Base.list([test]); | ||
|
||
process.stdout.write = stdoutWrite; | ||
errOut = stdout.join('\n'); | ||
errOut.should.not.match(/\- actual/); | ||
errOut.should.not.match(/\+ expected/); | ||
}); | ||
|
||
it('should not show diffs when expected is not defined', function () { | ||
var err = new Error('ouch') | ||
, errOut; | ||
|
||
var test = makeTest(err); | ||
|
||
Base.list([test]); | ||
|
||
errOut = stdout.join('\n'); | ||
errOut.should.not.match(/actual/); | ||
errOut.should.not.match(/expected/); | ||
errOut.should.not.match(/\- actual/); | ||
errOut.should.not.match(/\+ expected/); | ||
}); | ||
|
||
}); | ||
|
||
it('should not stringify strings', function () { | ||
var err = new Error('test'), | ||
stdout = [], | ||
stdoutWrite = process.stdout.write, | ||
errOut; | ||
|
||
err.actual = "a1"; | ||
err.expected = "e2"; | ||
err.showDiff = true; | ||
var test = { | ||
err: err, | ||
fullTitle: function () { | ||
return 'title'; | ||
} | ||
}; | ||
|
||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
}; | ||
var test = makeTest(err); | ||
|
||
Base.list([test]); | ||
|
||
process.stdout.write = stdoutWrite; | ||
|
||
errOut = stdout.join('\n'); | ||
|
||
errOut.should.not.match(/"/); | ||
errOut.should.match(/test/); | ||
errOut.should.match(/actual/); | ||
errOut.should.match(/expected/); | ||
|
||
errOut.should.match(/\- actual/); | ||
errOut.should.match(/\+ expected/); | ||
}); | ||
|
||
|
||
it('should stringify objects', function () { | ||
var err = new Error('test'), | ||
stdout = [], | ||
stdoutWrite = process.stdout.write, | ||
errOut; | ||
|
||
err.actual = {key:"a1"}; | ||
err.expected = {key:"e1"}; | ||
err.showDiff = true; | ||
var test = { | ||
err: err, | ||
fullTitle: function () { | ||
return 'title'; | ||
} | ||
}; | ||
var test = makeTest(err); | ||
|
||
process.stdout.write = function (string) { | ||
stdout.push(string); | ||
Base.list([test]); | ||
|
||
errOut = stdout.join('\n'); | ||
errOut.should.match(/"key"/); | ||
errOut.should.match(/test/); | ||
errOut.should.match(/\- actual/); | ||
errOut.should.match(/\+ expected/); | ||
}); | ||
|
||
it('should remove message from stack', function () { | ||
var err = { | ||
message: 'Error', | ||
stack: 'Error\nfoo\nbar', | ||
showDiff: false | ||
}; | ||
var test = makeTest(err); | ||
|
||
Base.list([test]); | ||
|
||
process.stdout.write = stdoutWrite; | ||
var errOut = stdout.join('\n').trim(); | ||
errOut.should.equal('1) test title:\n Error\n foo\n bar') | ||
}); | ||
|
||
errOut = stdout.join('\n'); | ||
it('should not modify stack if it does not contain message', function () { | ||
var err = { | ||
message: 'Error', | ||
stack: 'foo\nbar', | ||
showDiff: false | ||
}; | ||
var test = makeTest(err); | ||
|
||
errOut.should.match(/"key"/); | ||
errOut.should.match(/test/); | ||
errOut.should.match(/actual/); | ||
errOut.should.match(/expected/); | ||
Base.list([test]); | ||
|
||
var errOut = stdout.join('\n').trim(); | ||
errOut.should.equal('1) test title:\n Error\n foo\n bar') | ||
}); | ||
|
||
}); |