Skip to content

Commit

Permalink
Test: Source Displayed Even for Passed Test
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravmittal1995 authored and leobalter committed Mar 27, 2015
1 parent 4a3f898 commit 477e1f1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
16 changes: 15 additions & 1 deletion reporter/html.js
Expand Up @@ -699,7 +699,7 @@ QUnit.log(function( details ) {

QUnit.testDone(function( details ) {
var testTitle, time, testItem, assertList,
good, bad, testCounts, skipped,
good, bad, testCounts, skipped, sourceName,
tests = id( "qunit-tests" );

if ( !tests ) {
Expand Down Expand Up @@ -754,6 +754,20 @@ QUnit.testDone(function( details ) {
time.innerHTML = details.runtime + " ms";
testItem.insertBefore( time, assertList );
}

// Only add this information if stackTrace is supported
if ( details.source ) {
sourceName = document.createElement( "p" );
sourceName.innerHTML = "<strong>Source: </strong>" + details.source;
addClass( sourceName, "qunit-source" );
if ( bad === 0 ) {
addClass( sourceName, "qunit-collapsed" );
}
addEvent( testTitle, "click", function() {
toggleClass( sourceName, "qunit-collapsed" );
});
testItem.appendChild( sourceName );
}
});

if ( !defined.document || document.readyState === "complete" ) {
Expand Down
3 changes: 3 additions & 0 deletions src/test.js
Expand Up @@ -202,6 +202,9 @@ Test.prototype = {
assertions: this.assertions,
testId: this.testId,

// Source of Test
source: this.stack,

// DEPRECATED: this property will be removed in 2.0.0, use runtime instead
duration: this.runtime
});
Expand Down
7 changes: 7 additions & 0 deletions test/logs.js
Expand Up @@ -175,10 +175,16 @@ QUnit.test( module1Test2.name, function( assert ) {
// TODO: more tests for testDoneContext.assertions

delete testDoneContext.runtime;

// DEPRECATED: remove this delete when removing the duration property
delete testDoneContext.duration;

// Delete testDoneContext.assertions so we can easily jump to next assertion
delete testDoneContext.assertions;

// Delete testDoneContext.source
delete testDoneContext.source;

assert.deepEqual( testDoneContext, {
module: module1Context.name,
name: module1Test1.name,
Expand Down Expand Up @@ -259,6 +265,7 @@ QUnit.test( module2Test4.name, function( assert ) {

delete testDoneContext.runtime;
delete testDoneContext.duration;
delete testDoneContext.source;

assert.deepEqual( testDoneContext, {
assertions: [],
Expand Down
31 changes: 31 additions & 0 deletions test/reporter-html/reporter-html.js
Expand Up @@ -95,3 +95,34 @@ QUnit.test( "values", function( assert ) {
"Runtime includes beforeEach"
);
});

QUnit.module( "source" );

QUnit.test( "setup", function( assert ) {
assert.expect( 0 );
});

QUnit.test( "logs location", function( assert ) {
var previous = document.getElementById( "qunit-test-output-" + assert.test.testId )
.previousSibling;
var source = previous.lastChild;
var stack = QUnit.stack();

// Verify QUnit supported stack trace
if ( !stack ) {
assert.equal(
/(^| )qunit-source( |$)/.test( source.className ),
false,
"Don't add source information on non-supported environments"
);
return;
}

assert.ok( /(^| )qunit-source( |$)/.test( source.className ), "Source element exists" );
assert.equal( source.firstChild.innerHTML, "Source: " );

// test/reporter-html.js is a direct reference to this test file
assert.ok( /\/test\/reporter-html\/reporter-html\.js\:\d+/.test( source.innerHTML ),
"Source references to the current file and line number"
);
});

0 comments on commit 477e1f1

Please sign in to comment.