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: migrate test suites with skipped unit tests to karma #1753

Merged
merged 11 commits into from
Mar 11, 2020

Conversation

ravijayaramappa
Copy link
Contributor

@ravijayaramappa ravijayaramappa commented Mar 4, 2020

Details

Migrate following tests to karma suite

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:

  • Have tests for the proposed changes been added? ✅
  • Have you followed these instructions to clearly describe the issue being fixed or feature enhanced? ✅

GUS work item

W-7102290

@salesforce-best-lwc-internal
Copy link

⚠ Performance Regression

Best has detected that there is a 6.9% performance regression across your benchmarks.

Please click here to see more details.

Click to view significantly changed benchmarks

lwc-engine-benchmark

✅ Improvements base (fa28b98) target (b018ae2) trend
wc-append-1k.benchmark/benchmark-table-wc/append/1k 490.45 (± 5.87ms) 464.17 (± 10.38ms) -26.3ms (5.4%)
❌ Regressions base (fa28b98) target (b018ae2) trend
table-clear-1k.benchmark/benchmark-table/clear/1k 11.55 (± 0.19ms) 12.66 (± 0.30ms) +1.1ms (9.6%)
table-create-1k.benchmark/benchmark-table/create/1k 160.00 (± 1.51ms) 170.94 (± 2.15ms) +10.9ms (6.8%)
tablecmp-clear-1k.benchmark/benchmark-table-component/clear/1k 5.36 (± 0.09ms) 6.57 (± 0.33ms) +1.2ms (22.6%)
tablecmp-create-1k.benchmark/benchmark-table-component/create/1k 248.88 (± 2.21ms) 263.12 (± 2.86ms) +14.2ms (5.7%)

@ravijayaramappa ravijayaramappa marked this pull request as ready for review March 5, 2020 20:24
@ravijayaramappa ravijayaramappa requested a review from ekashida March 5, 2020 20:25
Copy link
Member

@ekashida ekashida left a 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?

@ravijayaramappa ravijayaramappa force-pushed the ravi/master/enable-unit-tests/W-7102290 branch from 8291e69 to 18746fe Compare March 6, 2020 15:36
@ravijayaramappa ravijayaramappa changed the title test: enable/remove skipped unit tests test: migrate test suites with skipped unit tests to karma Mar 6, 2020
@ravijayaramappa ravijayaramappa added the work-in-progress Work in progress label Mar 6, 2020
@ravijayaramappa ravijayaramappa removed the work-in-progress Work in progress label Mar 7, 2020
@@ -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() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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() {
Copy link
Member

Choose a reason for hiding this comment

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

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

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', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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';
Copy link
Member

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', () => {
Copy link
Member

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

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?

Comment on lines 336 to 344
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;
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick:

Suggested change
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')
));

Copy link
Member

@ekashida ekashida Mar 11, 2020

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?

Copy link
Contributor Author

@ravijayaramappa ravijayaramappa Mar 11, 2020

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

Copy link
Contributor Author

@ravijayaramappa ravijayaramappa Mar 11, 2020

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,
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

Suggested change
getHostChildNodes: getHostChildNodes,
getHostChildNodes,

Copy link
Contributor Author

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', () => {
Copy link
Member

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?

Suggested change
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', () => {

Copy link
Contributor Author

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', () => {
Copy link
Member

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

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?

Suggested change
// 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

Copy link
Contributor Author

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.

  1. createElement can fail to process the provided component class.
  2. 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);
Copy link
Member

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

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

Copy link
Member

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.

Copy link
Contributor Author

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

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.

Copy link
Member

@ekashida ekashida left a 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!

@pmdartus
Copy link
Member

Thanks for taking care of this @ravijayaramappa

@ravijayaramappa ravijayaramappa merged commit c1b56ec into master Mar 11, 2020
@ravijayaramappa ravijayaramappa deleted the ravi/master/enable-unit-tests/W-7102290 branch March 11, 2020 14:51
ekashida pushed a commit that referenced this pull request Apr 17, 2020
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants