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

HTML Reporter: Ensure attributes on qunit-fixture are reset. #1250

Merged
merged 3 commits into from
Jan 17, 2018

Conversation

rwjblue
Copy link
Contributor

@rwjblue rwjblue commented Jan 10, 2018

This change leverages Node.prototype.cloneNode to deeply clone the original qunit-fixture before any tests have started, then for each test replaces (using Node.prototype.replaceChild) the current qunit-fixture with a clone of the original.

Fixes #1224.

The prior tests were _only_ checking if the `innerHTML` matched our
expectations, and would not catch mutations to the element itself (e.g.
it being replaced with an element with a different tagName or its
attributes modified).
Copy link
Contributor

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small comment for now; I'll give this a proper review later.

values = [

/* initial value (see unshift below), */
/* initial value (see unshift below), */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused as to why this comment is duplicated.

Copy link
Contributor Author

@rwjblue rwjblue Jan 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments represent items in the values array here, and we now push the original value twice (the two values.unshift calls below).

Basically, there are now two tests that want to confirm that the default fixture is re-applied (where before we only had one)...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, okay, now I understand. (Kind of a weird setup for these tests, though...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INDEED! It was massively confusing for a bit, I tried to leave them a little easier to grok for next time but I definitely agree it is tricky as heck...

var resetFixtureType = typeof config.fixture;
if ( resetFixtureType === "string" ) {

// support user defined values for `config.fixture`
fixture.innerHTML = config.fixture;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we would still want to replace the outerHTML as well, right? Otherwise attributes on qunit-fixture won't reset when using user-defined fixture markup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, I'll add a test case for that and fix it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to address (with tests)...

This change leverages `Node.prototype.cloneNode` to deeply clone the
original `qunit-fixture` before any tests have started, then for each
test replaces (using `Node.prototype.replaceChild`) the current
`qunit-fixture` with a clone of the original.
Copy link
Member

@trentmwillis trentmwillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@trentmwillis trentmwillis merged commit 89dcd90 into qunitjs:master Jan 17, 2018
Turbo87 added a commit to Turbo87/ember.js that referenced this pull request Dec 8, 2018
Since qunitjs/qunit#1250 was merged this should no longer be needed
@rwjblue rwjblue deleted the clone-fixture branch August 17, 2020 23:00
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.

Attributes on qunit-fixture are leaked across tests.
3 participants