-
Notifications
You must be signed in to change notification settings - Fork 405
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: migrate test suites with skipped unit tests to karma #1753
test: migrate test suites with skipped unit tests to karma #1753
Conversation
⚠ Performance RegressionBest has detected that there is a Please click here to see more details. Click to view significantly changed benchmarkslwc-engine-benchmark
|
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.
These tests rely on compileTemplate
which we want to move away from (#1295). Could we move these tests to karma integration and enable them there?
restriction was removed via #1362
8291e69
to
18746fe
Compare
@@ -104,3 +105,9 @@ describe('inheritance', () => { | |||
expect(elm.overriddenMethod()).toBe('overridden - child'); | |||
}); | |||
}); | |||
|
|||
it('should not log an error when initializing api value to null', function() { |
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.
it('should not log an error when initializing api value to null', function() { | |
it('should not log an error when initializing api value to null', () => { |
@@ -91,6 +93,12 @@ describe('object mutations', () => { | |||
expect(elm.shadowRoot.querySelector('.obj').textContent).toBe('1'); | |||
}); | |||
}); | |||
|
|||
it('should not log an error when setting tracked value to null', function() { |
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.
it('should not log an error when setting tracked value to null', function() { | |
it('should not log an error when setting tracked value to null', () => { |
@@ -124,3 +132,13 @@ describe('array mutations', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('non-observable values', () => { | |||
it('should not throw error when accessing a non-observable property from tracked property when not rendering', function() { |
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.
it('should not throw error when accessing a non-observable property from tracked property when not rendering', function() { | |
it('should not throw an error when accessing a non-observable property from a tracked property when not rendering', () => { |
describe('with locker', () => { | ||
it('should support manual construction', () => { | ||
const elm = createElement('x-parent', { is: LockerIntegration }); | ||
document.body.appendChild(elm); |
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.
We should check in this case if the element is rendered properly, by checking the DOM output.
expect(child.assignedSlot).toBe(null); | ||
}); | ||
|
||
it('should return correct slot when native element is slotted', () => { |
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.
it('should return correct slot when native element is slotted', () => { | |
it('should return the correct slot when native element is slotted', () => { |
expect(child.assignedSlot).toBe(slot); | ||
}); | ||
|
||
it('should return correct slot when custom element is slotted', () => { |
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.
it('should return correct slot when custom element is slotted', () => { | |
it('should return the correct slot when custom element is slotted', () => { |
expect(child.assignedSlot).toBe(null); | ||
}); | ||
|
||
it('should return correct slot when text is slotted', () => { |
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.
it('should return correct slot when text is slotted', () => { | |
it('should return the correct slot when text is slotted', () => { |
@@ -0,0 +1,62 @@ | |||
import { createElement } from 'lwc'; |
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 would suggest adding a test for named slots as well.
|
||
import CustomInstanceSetter from 'x/customInstanceSetter'; | ||
|
||
describe('#data layer', () => { |
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 description doesn't reflect what the test is doing.
@@ -0,0 +1,72 @@ | |||
import { createElement } from 'lwc'; |
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.
There is a lot of boilerplate code in the global HTML properties test. Is it something we can refactor to share the common test code?
var filtered = []; | ||
const childNodes = host.childNodes; | ||
for (var i = 0; i < childNodes.length; i++) { | ||
var n = childNodes[i]; | ||
if (!(n.nodeType === Node.COMMENT_NODE && n.tagName.startsWith('#shadow-root'))) { | ||
filtered.push(n); | ||
} | ||
} | ||
return filtered; |
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.
Nitpick:
var filtered = []; | |
const childNodes = host.childNodes; | |
for (var i = 0; i < childNodes.length; i++) { | |
var n = childNodes[i]; | |
if (!(n.nodeType === Node.COMMENT_NODE && n.tagName.startsWith('#shadow-root'))) { | |
filtered.push(n); | |
} | |
} | |
return filtered; | |
return Array.from(host.childNodes).filter(n => !( | |
n.nodeType === Node.COMMENT_NODE && n.tagName.startsWith('#shadow-root') | |
)); |
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 saw that this used to be:
function getHostChildNodes(host) {
return [...host.childNodes].filter(n => {
return n.nodeType !== Node.COMMENT_NODE && !n.tagName.startsWith('#shadow-root');
});
}
This was incorrect because we only wanted to filter out #shadow-root
comment nodes, right?
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.
test-utils is not transpiled down to ES5, it is appended as-is. So will use something like this
return Array.prototype.slice.call(host.childNodes).filter(function(n) {
return !( n.nodeType === Node.COMMENT_NODE && n.tagName.startsWith('#shadow-root'));
});
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.
This was incorrect because we only wanted to filter out #shadow-root comment nodes, right?
yes. It was failing if n
was a text node.
return { | ||
registerForLoad: registerForLoad, | ||
clearRegister: clearRegister, | ||
load: load, | ||
extractDataIds: extractDataIds, | ||
extractShadowDataIds: extractShadowDataIds, | ||
getHostChildNodes: getHostChildNodes, |
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.
Nit:
getHostChildNodes: getHostChildNodes, | |
getHostChildNodes, |
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.
Same as above, no es6 syntax.
@@ -124,3 +132,13 @@ describe('array mutations', () => { | |||
}); | |||
}); | |||
}); | |||
|
|||
describe('non-observable values', () => { | |||
it('should not throw an error when accessing a non-observable property from a tracked property when not rendering', () => { |
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.
This test seems weirdly specific, I wonder if it's to prevent a regression. Do you know if there is a related issue for it?
it('should not throw an error when accessing a non-observable property from a tracked property when not rendering', () => { | |
it('should not throw an error when accessing a non-observable property from a tracked property before render', () => { |
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.
Added back in 2017 and no linked issue a34c102#diff-048a3be16e6b62a0fcdb17e0b220b01f
|
||
import LockerIntegration from 'x/lockerIntegration'; | ||
|
||
describe('integration', () => { |
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.
Nit: I think we should either collapse these two describe
blocks into locker integration
or remove them completely since our infrastructure implicitly uses the filename as the top level describe
.
it('should support manual construction', () => { | ||
const elm = createElement('x-secure-parent', { is: LockerIntegration }); | ||
document.body.appendChild(elm); | ||
// Verifying that shadow tree was created to ensure the component class was successfull processed |
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.
This comment suggests to me that if the component was not successfully processed the host element will be rendered without its shadow. Is this correct?
// Verifying that shadow tree was created to ensure the component class was successfull processed | |
// Verifying that shadow tree was created to ensure the component class was successfully processed |
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.
There are two ways this can fail.
createElement
can fail to process the provided component class.- Once the host is connected to the dom, the engine can fail to run the lifecycle hooks of the component class. eg: render() in this testcase
/\[LWC error\]: Invalid id value "undefined". The id attribute must contain a non-empty string./ | ||
); | ||
const child = elm.shadowRoot.querySelector('x-child'); | ||
expect(child.getAttribute('id')).toEqual(null); |
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 like this skipped test was incomplete. x-child
doesn't have an id
attribute so we need to add it. I tested it and saw that the value should be 'undefined'
.
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 the test. It seems like there is a difference in behavior for custom elements v/s standard html elements. When id value is undefined, standard html element return null
.
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.
Yeah, it has to do with how we set content vs IDL attribute for native vs custom elements.
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.
Logged #1769 to document the difference. Added a comment in the test to link to the issue.
/\[LWC error\]: Invalid id value "". The id attribute must contain a non-empty string./ | ||
); | ||
const child = elm.shadowRoot.querySelector('x-child'); | ||
expect(child.getAttribute('id')).toEqual(null); |
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 like this skipped test was incomplete. x-child
doesn't have an id
attribute so we need to add it. I tested it and saw that the value should be an empty string.
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 great, thanks Ravi!
Thanks for taking care of this @ravijayaramappa |
* test: remove unit tests related to global attribute restriction restriction was removed via #1362 * test: update error message in scoped-ids.spec.ts * test: update test to match <slot> element spec * test: remove unit test that was testing non-existent functions * test: migrate tests to integration-karma * test: migrate scoped-ids.spec to karma suite * test: migrate html-element.spec.ts to karma * test: migrate traverse.spec.ts to karma suite (cherry picked from commit c1b56ec)
Details
Migrate following tests to karma suite
packages/@lwc/engine/src/framework/__tests__/html-element.spec.ts
remove unit tests related to global attribute restriction, restriction was removed via chore: remove attribute mutation restrictions #1362
packages/@lwc/engine/src/framework/__tests__/scoped-ids.spec.ts
Error message updated via refactor(engine): clean up error messages #1193
packages/@lwc/engine/src/__tests__/traverse.spec.ts
element's childNodes value will reflect default content. Updating test to follow spec.
Removed redundant tests that were testing lifecycle callbacks.
packages/@lwc/engine/src/__tests__/focus.spec.ts
Removed skipped tests that were meant to test non-existent functionality. Resurrect if we solve [refactor tests]: find ways to test isFocusable and isTabbable in a browser #1341
Does this PR introduce breaking changes?
No, it does not introduce breaking changes.
If yes, please describe the impact and migration path for existing applications.
The PR fulfills these requirements:
GUS work item
W-7102290