-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
vdemedes
committed
Dec 21, 2015
1 parent
b02e5ec
commit 7639370
Showing
6 changed files
with
200 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
var format = require('util').format; | ||
|
||
// Parses stack trace and extracts original function name, file name and line. | ||
function getSourceFromStack(stack, index) { | ||
return stack | ||
.split('\n') | ||
.slice(index, index + 1) | ||
.join('') | ||
.replace(/^\s+at /, ''); | ||
} | ||
|
||
exports.start = function () { | ||
return 'TAP version 13'; | ||
}; | ||
|
||
var i = 0; | ||
|
||
exports.test = function (test) { | ||
var output; | ||
|
||
if (test.error) { | ||
output = [ | ||
'# ' + test.title, | ||
format('not ok %d - %s', ++i, test.error.message), | ||
' ---', | ||
' operator: ' + test.error.operator, | ||
' expected: ' + test.error.expected, | ||
' actual: ' + test.error.actual, | ||
' at: ' + getSourceFromStack(test.error.stack, 3), | ||
' ...' | ||
]; | ||
} else { | ||
output = [ | ||
'# ' + test.title, | ||
format('ok %d - %s', ++i, test.title) | ||
]; | ||
} | ||
|
||
return output.join('\n'); | ||
}; | ||
|
||
exports.unhandledError = function (err) { | ||
var output = [ | ||
'# ' + err.message, | ||
format('not ok %d - %s', ++i, err.message), | ||
' ---', | ||
' name: ' + err.name, | ||
' at: ' + getSourceFromStack(err.stack, 1), | ||
' ...' | ||
]; | ||
|
||
return output.join('\n'); | ||
}; | ||
|
||
exports.finish = function (passCount, failCount, rejectionCount, exceptionCount) { | ||
var output = [ | ||
'', | ||
'1..' + (passCount + failCount), | ||
'# tests ' + (passCount + failCount), | ||
'# pass ' + passCount, | ||
'# fail ' + (failCount + rejectionCount + exceptionCount), | ||
'' | ||
]; | ||
|
||
return output.join('\n'); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,89 @@ | ||
'use strict'; | ||
var test = require('tap').test; | ||
var tap = require('../lib/tap'); | ||
|
||
test('start', function (t) { | ||
t.is(tap.start(), 'TAP version 13'); | ||
t.end(); | ||
}); | ||
|
||
test('passing test', function (t) { | ||
var actualOutput = tap.test({ | ||
title: 'passing' | ||
}); | ||
|
||
var expectedOutput = [ | ||
'# passing', | ||
'ok 1 - passing' | ||
].join('\n'); | ||
|
||
t.is(actualOutput, expectedOutput); | ||
t.end(); | ||
}); | ||
|
||
test('failing test', function (t) { | ||
var actualOutput = tap.test({ | ||
title: 'failing', | ||
error: { | ||
message: 'false == true', | ||
operator: '==', | ||
expected: true, | ||
actual: false, | ||
stack: ['', '', '', ' at Test.fn (test.js:1:2)'].join('\n') | ||
} | ||
}); | ||
|
||
var expectedOutput = [ | ||
'# failing', | ||
'not ok 2 - false == true', | ||
' ---', | ||
' operator: ==', | ||
' expected: true', | ||
' actual: false', | ||
' at: Test.fn (test.js:1:2)', | ||
' ...' | ||
].join('\n'); | ||
|
||
t.is(actualOutput, expectedOutput); | ||
t.end(); | ||
}); | ||
|
||
test('unhandled error', function (t) { | ||
var actualOutput = tap.unhandledError({ | ||
message: 'unhandled', | ||
name: 'TypeError', | ||
stack: ['', ' at Test.fn (test.js:1:2)'].join('\n') | ||
}); | ||
|
||
var expectedOutput = [ | ||
'# unhandled', | ||
'not ok 3 - unhandled', | ||
' ---', | ||
' name: TypeError', | ||
' at: Test.fn (test.js:1:2)', | ||
' ...' | ||
].join('\n'); | ||
|
||
t.is(actualOutput, expectedOutput); | ||
t.end(); | ||
}); | ||
|
||
test('results', function (t) { | ||
var passCount = 1; | ||
var failCount = 2; | ||
var rejectionCount = 3; | ||
var exceptionCount = 4; | ||
|
||
var actualOutput = tap.finish(passCount, failCount, rejectionCount, exceptionCount); | ||
var expectedOutput = [ | ||
'', | ||
'1..' + (passCount + failCount), | ||
'# tests ' + (passCount + failCount), | ||
'# pass ' + passCount, | ||
'# fail ' + (failCount + rejectionCount + exceptionCount), | ||
'' | ||
].join('\n'); | ||
|
||
t.is(actualOutput, expectedOutput); | ||
t.end(); | ||
}); |