-
Notifications
You must be signed in to change notification settings - Fork 779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tap reporter (prototype yet - please come and discuss) #972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
(function() { | ||
|
||
function reporter( rep ) { | ||
if ( rep === "tap" ) { | ||
tapReporter(); | ||
} | ||
}; | ||
|
||
reporter.print = function( val ) { | ||
console.log( val ); | ||
}; | ||
|
||
QUnit.reporter = reporter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely doesn't belong in reporter/tap.js, and I still have issues with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
definitely, I agree. I'll review this, crossing with the efforts on the js-reporter and provide some good rebased thing. |
||
|
||
function tapReporter() { | ||
var testCount = 0; | ||
var failed = 0; | ||
|
||
QUnit.begin( function() { | ||
QUnit.reporter.print( "TAP version 13" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted something I can patch/replace/inspect. Do you have any other suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be specific to the TAP reporter, or even better to a TAP reporter instance. Testing code code then boil down to something like |
||
} ); | ||
|
||
QUnit.done( function( details ) { | ||
var output = [ | ||
"", | ||
"1.." + testCount, | ||
"# tests " + testCount, | ||
"# pass " + ( testCount - failed ) | ||
]; | ||
|
||
QUnit.reporter.print( output.join( "\n" ) ); | ||
} ); | ||
|
||
QUnit.moduleStart( function( details ) { | ||
QUnit.reporter.print( "# module: " + details.name ); | ||
} ); | ||
|
||
QUnit.testDone( function( details ) { | ||
var assertion; | ||
var failedMessage; | ||
var output; | ||
var i = 0; | ||
|
||
testCount++; | ||
|
||
output = "ok " + testCount + " - "; | ||
|
||
if ( details.skipped ) { | ||
output += "# SKIP " + details.name; | ||
} else if ( details.failed == 0 ) { | ||
output += details.name; | ||
} else { | ||
failed++; | ||
output = "not " + output + details.name; | ||
|
||
for ( i = 0; i < details.assertions.length; i++ ) { | ||
assertion = details.assertions[ i ]; | ||
if ( assertion.result ) { | ||
continue; | ||
} | ||
failedMessage = [ | ||
"", | ||
" ---", | ||
" message: '" + assertion.message + "'", | ||
" severity: fail", | ||
" ..." | ||
]; | ||
|
||
output += failedMessage.join( "\n" ); | ||
} | ||
} | ||
|
||
QUnit.reporter.print( output ); | ||
} ); | ||
}; | ||
|
||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>QUnit Test Suite - Tap Reporter</title> | ||
<link rel="stylesheet" href="../dist/qunit.css"> | ||
<script src="../dist/qunit.js"></script> | ||
<script src="../reporter/tap.js"></script> | ||
<script src="tap.js"></script> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* globals console:true */ | ||
|
||
var storedResults = []; | ||
var originalPrint = QUnit.reporter.print; | ||
QUnit.reporter.print = function( output ) { | ||
storedResults.push( output ); | ||
}; | ||
|
||
QUnit.config.reorder = false; | ||
|
||
QUnit.reporter( "tap" ); | ||
|
||
QUnit.module( "print function" ); | ||
|
||
QUnit[ console && console.log ? "test" : "skip" ]( "prints to console.log", function( assert ) { | ||
var results = []; | ||
|
||
// Duck punch console.log | ||
this.originalLog = console.log; | ||
console.log = function( arg ) { | ||
results.push( arg ); | ||
}; | ||
|
||
originalPrint( "foo", "bar" ); | ||
originalPrint( "baz" ); | ||
|
||
assert.strictEqual( results.length, 2 ); | ||
|
||
assert.strictEqual( results[ 0 ], "foo", "calls console.log fn" ); | ||
assert.strictEqual( results[ 1 ], "baz" ); | ||
|
||
console.log = this.originalLog; | ||
} ); | ||
|
||
QUnit.module( "tap reporter - samples" ); | ||
|
||
QUnit.test( "this test will pass", function( assert ) { | ||
assert.ok( true ); | ||
assert.equal( 1, 1 ); | ||
} ); | ||
|
||
QUnit.test( "async tests that pass", function( assert ) { | ||
assert.ok( true ); | ||
var done = assert.async(); | ||
|
||
setTimeout( function() { | ||
assert.ok( true ); | ||
done(); | ||
}, 13 ); | ||
} ); | ||
|
||
QUnit.module( "tap reporter - samples #2" ); | ||
|
||
QUnit.test( "this test will pass", function( assert ) { | ||
assert.ok( true ); | ||
assert.equal( 1, 1 ); | ||
} ); | ||
|
||
QUnit.test( "async tests that pass", function( assert ) { | ||
assert.ok( true ); | ||
var done = assert.async(); | ||
|
||
setTimeout( function() { | ||
assert.ok( true ); | ||
done(); | ||
}, 13 ); | ||
} ); | ||
|
||
var once = true; | ||
var expected = [ | ||
"TAP version 13", | ||
"# module: print function", | ||
"ok 1 - prints to console.log", | ||
"# module: tap reporter - samples", | ||
"ok 2 - this test will pass", | ||
"ok 3 - async tests that pass", | ||
"# module: tap reporter - samples #2", | ||
"ok 4 - this test will pass", | ||
"ok 5 - async tests that pass", | ||
"", | ||
"1..5", | ||
"# tests 5", | ||
"# pass 5" | ||
].join( "\n" ); | ||
|
||
QUnit.done( function() { | ||
if ( once ) { | ||
once = false; | ||
QUnit.module( "tap reporter" ); | ||
QUnit.test( "final tests", function( assert ) { | ||
|
||
// Remove the current module | ||
storedResults.pop(); | ||
assert.equal( storedResults.join( "\n" ), expected ); | ||
} ); | ||
} | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this a bit more generic? Like:
I guess this depends on the circumstances under which
print
will be used.