mirror of https://github.com/lukechilds/ava.git
vdemedes
9 years ago
committed by
Sindre Sorhus
6 changed files with 199 additions and 9 deletions
@ -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'); |
|||
}; |
After Width: | Height: | Size: 15 KiB |
@ -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(); |
|||
}); |
Loading…
Reference in new issue