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
Test: Source Displayed Even for Passed Test #758
Conversation
if ( source ) { | ||
details.source = source; | ||
} | ||
source = sourceFromStacktrace(); |
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.
You can pass a parameter to sourceFromStacktrace
to set the exact line you need to cap end send. The default (no parameter) works fine when the result is falsy, but it's not the same when it pass.
The example below - of the tests running with this current changes - seems we need to set the parameter to start with that second line (at file:///Users/leobalter/dev/qunit/test/logs.js:120
).
Also, it's probably good to break this information to give just a single line location.
" at temp//@1_Users@1_leobalter@1_dev@1_qunit@1_dist@1_qunit.js:9
at file:///Users/leobalter/dev/qunit/test/logs.js:120
at temp//@1_Users@1_leobalter@1_dev@1_qunit@1_dist@1_qunit.js:9
at temp//@1_Users@1_leobalter@1_dev@1_qunit@1_dist@1_qunit.js:9
at process (temp//@1_Users@1_leobalter@1_dev@1_qunit@1_dist@1_qunit.js:9)
at begin (temp//@1_Users@1_leobalter@1_dev@1_qunit@1_dist@1_qunit.js:9)
at temp//@1_Users@1_leobalter@1_dev@1_qunit@1_dist@1_qunit.js:9"
@leobalter Done. Please Review |
} | ||
source = sourceFromStacktrace( 4 ); | ||
if ( source ) { | ||
details.source = source; |
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.
As I mentioned before, the sourceFromStacktrace parameter must be different when the test fail, otherwise you're just gonna solve the problem when it pass, before it was good when the tests failed.
#706 is about showing the location of passed tests(!), not passed assertions. |
@jzaefferer @leobalter Made Changes. Please Review |
@jzaefferer Made it collapsable. Please Review |
@@ -106,7 +106,7 @@ QUnit.test( "setup", function( assert ) { | |||
QUnit.test( "basics", function( assert ) { | |||
assert.expect( 2 ); | |||
var previous = getPreviousTests( /^setup$/, /^timing$/ )[ 0 ], | |||
runtime = previous.lastChild.previousSibling; | |||
runtime = previous.lastChild.previousSibling.previousSibling; |
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.
Here's a good opportunity to include tests for these changes.
Would you include a test with a regexp containing the static part of the source line?
Working good for me, now it's just about to add a test and fix the code style issues. |
@@ -723,6 +727,10 @@ QUnit.testDone(function( details ) { | |||
time.innerHTML = details.runtime + " ms"; | |||
testItem.insertBefore( time, assertList ); | |||
} | |||
|
|||
sourceName.innerHTML = "<b class='counts'>Source: </b>" + details.source; | |||
assertList.parentNode.insertBefore(sourceName, assertList.nextSibling); |
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.
missing space before and after arguments list.
assertList.parentNode.insertBefore( sourceName, assertList.nextSibling );
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.
I was playing with the code and we can do this easier:
sourceName = document.createElement( "p" );
sourceName.innerHTML = "<strong>Source: </strong>" + details.source;
addClass( sourceName, "qunit-collapsed qunit-source" );
addEvent( testTitle, "click", function() {
toggleClass( sourceName, "qunit-collapsed" );
});
testItem.appendChild( sourceName );
- The source can be inserted to any test
- it shouldn't use
counts
class, but just a strong tag on theSource:
text. - the source element now uses a
qunit-source
class. - the click event is made individually, this way you can still have the source information on skipped tests
- it is appended on the testItem element.
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.
@leobalter I tried the above. But gives error for addEvent because it calls addevent two time for testTitle click.
Changed innerhtml to strong and used appendChild instead of addBefore.
Seems to be working fine now.
@leobalter Hey, What test is needed? Can u explain a bit more? |
@leobalter Hey, Made the changes. Can u explain the test that is needed?? |
you need to add test for the changes you made, assert the previous test added a source line. |
also: #758 (comment) |
@leobalter How do i add test for the change?? |
HTML reporter output for passing tests looks good to me now. May want to hide that for failing tests, since the failing assertion already includes source lines. |
I'm writing the tests and will land them as soon as I fix this PR on IE6 to 9, they're currently saying "Source: undefined" |
@jzaefferer Hey, IMHO, i think that we should keep the source even for failed test. Since failed test only show lines of fail assertion, a failed test can still have some passed assertions as well. Also the test can be big and the assertion called much later than where the test starts. This is what i think. I could be wrong. Please let me know if i should hide it for failed assertions. |
@leobalter Any change needed? or should i squash the commits? |
@gauravmittal1995, let the squash to happen only before merging. So far we need to wait @jzaefferer to answer my comments or you can try the approach he suggested, in a new commit in the PR. If @jzaefferer agrees with my arguments, we're probably good to land, but we need to wait the next time he's available. Different time zones makes it take more time. |
@leobalter I think i will wait for @jzaefferer to reply to your comments before making the changes he asked for |
Discussed this with @leobalter in a private chat. He's going to do some tests to verify support for |
@jzaefferer ok ... thanks |
@leobalter since #773 doesn't change much, what's the verdict for this PR? |
I don't like to add tests based on the log to verify the feature. But we can replace that Other way, without adding logging hooks: In the tests just copy the content from |
I'm not sure what you're suggesting here. Can you please clarify, maybe using an example?
That seems fine, since all the complexity lives in the |
I didn't write an example before because it would be long and ugly, but as you agreed with the second option I would just stick with that. |
👍 |
@gauravmittal1995, #773 is landed, let's finish this one! |
I've got the branch and fixed this, but I got one remaining issue. Safari 5.1 fails the tests as the stack is not defined because of this line I can't have the same detection on the test js file. There's nothing beyond the userAgent to avoid this. |
https://github.com/jquery/qunit/compare/jquery:master...leobalter:gauravmittal1995-Source?expand=1 Here's the 2 commits fixing this PR. My branch is also rebased with master. The second one is not the best thing as it determines Safari 5.1 (the sourceURL exception) via userAgent. I can't find anything else to avoid this. |
jQuery Core exports |
For now, we can land this as the flags are already internal (right?), and replace the tests when QUnit.stack is ready, or wait until the other PR to land. |
Let's create a separate issue and merge this. |
From internal sourceFromStacktrace method Ref qunitjs#758
From internal sourceFromStacktrace method Ref qunitjs#758 Closes qunitjs#801
@leobalter Do i rebase this with https://github.com/jquery/qunit/compare/jquery:master...leobalter:gauravmittal1995-Source?expand=1 ??? |
From internal sourceFromStacktrace method Ref qunitjs#758 Closes qunitjs#801
From internal sourceFromStacktrace method Ref qunitjs#758 Closes qunitjs#801
Related to : #706