Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

gauravmittal1995
Copy link
Contributor

Related to : #706

if ( source ) {
details.source = source;
}
source = sourceFromStacktrace();
Copy link
Member

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"

@gauravmittal1995
Copy link
Contributor Author

@leobalter Done. Please Review

}
source = sourceFromStacktrace( 4 );
if ( source ) {
details.source = source;
Copy link
Member

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.

@jzaefferer
Copy link
Member

#706 is about showing the location of passed tests(!), not passed assertions.

@gauravmittal1995
Copy link
Contributor Author

@jzaefferer @leobalter Made Changes. Please Review

@jzaefferer
Copy link
Member

The output needs to be inside the collapsed element, so that its only shown when opening details of a test. Currently this source line is shown for every test, which looks pretty bad.

...

@gauravmittal1995
Copy link
Contributor Author

@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;
Copy link
Member

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?

@leobalter
Copy link
Member

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);
Copy link
Member

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 );

Copy link
Member

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 the Source: 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.

Copy link
Contributor Author

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.

@gauravmittal1995
Copy link
Contributor Author

@leobalter Hey, What test is needed? Can u explain a bit more?

@gauravmittal1995
Copy link
Contributor Author

@leobalter Hey, Made the changes. Can u explain the test that is needed??

@leobalter
Copy link
Member

you need to add test for the changes you made, assert the previous test added a source line.

@leobalter
Copy link
Member

also: #758 (comment)

@gauravmittal1995
Copy link
Contributor Author

@leobalter How do i add test for the change??

@jzaefferer
Copy link
Member

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.

@leobalter
Copy link
Member

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"

@gauravmittal1995
Copy link
Contributor Author

@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.
Also this will also be consistent with the passed tests.

This is what i think. I could be wrong. Please let me know if i should hide it for failed assertions.

@gauravmittal1995
Copy link
Contributor Author

@leobalter Any change needed? or should i squash the commits?

@leobalter
Copy link
Member

@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.

@gauravmittal1995
Copy link
Contributor Author

@leobalter I think i will wait for @jzaefferer to reply to your comments before making the changes he asked for

@jzaefferer
Copy link
Member

Discussed this with @leobalter in a private chat. He's going to do some tests to verify support for Error().stack, which should help making an informed decision here.

@gauravmittal1995
Copy link
Contributor Author

@jzaefferer ok ... thanks

leobalter added a commit to leobalter/qunit that referenced this pull request Mar 9, 2015
@jzaefferer
Copy link
Member

@leobalter since #773 doesn't change much, what's the verdict for this PR?

@leobalter
Copy link
Member

I don't like to add tests based on the log to verify the feature. But we can replace that if ( Error.stack() ) by something related to details.source if is defined in a testDone after the "setup" test (which would require to hook removal later).

Other way, without adding logging hooks:

In the tests just copy the content from sourceFromStacktrace (without the return statement) for to replace the if condition in the tests.

@jzaefferer
Copy link
Member

I don't like to add tests based on the log to verify the feature. But we can replace that if ( Error.stack() ) by something related to details.source if is defined in a testDone after the "setup" test (which would require to hook removal later).

I'm not sure what you're suggesting here. Can you please clarify, maybe using an example?

In the tests just copy the content from sourceFromStacktrace (without the return statement) for to replace the if condition in the tests.

That seems fine, since all the complexity lives in the extract... method.

@leobalter
Copy link
Member

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.

@jzaefferer
Copy link
Member

👍

leobalter added a commit to leobalter/qunit that referenced this pull request Mar 26, 2015
@leobalter
Copy link
Member

@gauravmittal1995, #773 is landed, let's finish this one!

@leobalter
Copy link
Member

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.

@leobalter
Copy link
Member

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.

@jzaefferer
Copy link
Member

jQuery Core exports $.support, even though it mostly uses those flags internally. How about we export QUnit.stacktraceSupportIsThere (not my naming day) and use that in tests? Maybe we can use the flag internally as well, not sure.

@leobalter
Copy link
Member

QUnit.stack should be fine and would export a standardized Error stack. I'll push this in a separate PR so we can proper discuss it.

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.

@jzaefferer
Copy link
Member

Let's create a separate issue and merge this.

leobalter added a commit to leobalter/qunit that referenced this pull request Mar 27, 2015
From internal sourceFromStacktrace method

Ref qunitjs#758
@leobalter leobalter mentioned this pull request Mar 27, 2015
leobalter added a commit to leobalter/qunit that referenced this pull request Mar 27, 2015
From internal sourceFromStacktrace method

Ref qunitjs#758
Closes qunitjs#801
leobalter pushed a commit to leobalter/qunit that referenced this pull request Mar 27, 2015
@gauravmittal1995
Copy link
Contributor Author

leobalter added a commit to leobalter/qunit that referenced this pull request Apr 13, 2015
From internal sourceFromStacktrace method

Ref qunitjs#758
Closes qunitjs#801
leobalter pushed a commit to leobalter/qunit that referenced this pull request Apr 13, 2015
leobalter added a commit to leobalter/qunit that referenced this pull request Apr 14, 2015
From internal sourceFromStacktrace method

Ref qunitjs#758
Closes qunitjs#801
@leobalter leobalter closed this in 9498355 Apr 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants