-
Notifications
You must be signed in to change notification settings - Fork 780
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
Conversation
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).
9b3986e
to
f60890e
Compare
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.
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), */ |
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.
Confused as to why this comment is duplicated.
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.
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)...
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.
Oh, okay, now I understand. (Kind of a weird setup for these tests, though...)
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.
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...
runner/fixture.js
Outdated
var resetFixtureType = typeof config.fixture; | ||
if ( resetFixtureType === "string" ) { | ||
|
||
// support user defined values for `config.fixture` | ||
fixture.innerHTML = config.fixture; |
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.
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.
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.
Great point, I'll add a test case for that and fix it up.
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.
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.
f60890e
to
aec00d5
Compare
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.
Looks good to me, thanks!
Since qunitjs/qunit#1250 was merged this should no longer be needed
This change leverages
Node.prototype.cloneNode
to deeply clone the originalqunit-fixture
before any tests have started, then for each test replaces (usingNode.prototype.replaceChild
) the currentqunit-fixture
with a clone of the original.Fixes #1224.