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

switch to @brightspace-ui/testing fixture #3764

Merged
merged 3 commits into from
Jun 21, 2023

Conversation

dlockhart
Copy link
Member

The vast majority of the changes here are just adjusting the import location, however having fixture now wait for everything to be ready did require adjusting a few tests that were dependent on it not doing that.

Once this is merged I'll do a separate pull request to remove all the test code that's manually waiting for nested element updateCompletes.

@github-actions
Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://pr-3764-brightspace-ui-core.d2l.dev/

Note
The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

@@ -17,7 +17,8 @@ describe('d2l-dialog', () => {
describe('focus management', () => {

it('should focus on close button if no focusable elements inside', async() => {
const el = await fixture(html`<d2l-dialog opened>not focusable</d2l-dialog>`);
const el = await fixture(html`<d2l-dialog>not focusable</d2l-dialog>`);
el.opened = true;
Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed previously, these types of tests where an event is fired as part of boot-up need to be adjusted to control when the event gets fired themselves.

@@ -62,7 +61,6 @@ describe('d2l-dropdown', () => {
beforeEach(async() => {
dropdown = await fixture(normalFixture);
content = dropdown.querySelector('d2l-dropdown-content');
await content.updateComplete;
Copy link
Member Author

Choose a reason for hiding this comment

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

Will do more of this kind of thing in a follow-up PR.

@@ -24,7 +24,6 @@ describe('d2l-hierarchical-view', () => {
const el = await fixture(viewsFixture);
view1 = el.querySelector('#view1');
view2 = el.querySelector('#view2');
await oneEvent(view1, 'd2l-hierarchical-view-resize');
Copy link
Member Author

Choose a reason for hiding this comment

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

This event has already been fired by the time fixture resolves.

@@ -103,7 +103,7 @@ describe('d2l-input-search', () => {

let clock;
beforeEach(() => {
clock = useFakeTimers();
clock = useFakeTimers({ toFake: ['clearTimeout', 'setTimeout'] });
Copy link
Member Author

Choose a reason for hiding this comment

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

The new fixture relies on await nextFrame() when it resets stuff, so we need to be more targeted with our mocking otherwise requestAnimationFrame gets mocked.

Copy link
Contributor

Choose a reason for hiding this comment

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

This would be good to note on the eventual README docs

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep I've already included it in the draft upgrade guide, but I could definitely see it going into a README as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

These tests were VERY flaky in Firefox. I spent the entire day trying to figure out why occasionally the handle loses focus before the keys can be sent to it but got nowhere. So I ended up implementing a "retry".

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll have to keep an eye on these, to see if one retry tends to be enough. Longer tests make flake that much more painful

actionArea.dispatchEvent(new Event('click'));
});
await oneEvent(actionArea, 'click');
element.activateKeyboardMode();
Copy link
Member Author

Choose a reason for hiding this comment

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

Activating keyboard mode does everything that clicking the button does.

}
);

const elem = await fixture(`
const elemPromise = fixture(`
<d2l-menu>
<d2l-menu-item text="fast"></d2l-menu-item>
<${delayedUpdateMenuItem}></${delayedUpdateMenuItem}>
<span>not a menu item</span>
</d2l-menu>
`);
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to rework how this "slow element" works since fixture now won't resolve until everything is ready anyway.

bubbles: false,
composed: false
}))
);
Copy link
Member Author

Choose a reason for hiding this comment

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

No longer needed now that fixture waits for this for us.

@@ -92,7 +91,7 @@ describe('LabelledMixin', () => {
const labelledElem = elem.querySelector('[labelled-by="label1"]');
const labelElem = elem.querySelector('#label1');
labelElem.textContent = 'new label value';
await nextFrame();
Copy link
Member Author

Choose a reason for hiding this comment

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

This was really flaky so I switched it to use an event instead of rely on rAF.

@@ -21,7 +21,7 @@ jobs:
run: npm run lint:style
playwright:
name: Accessibility and Unit Tests
timeout-minutes: 10
timeout-minutes: 15
Copy link
Member Author

Choose a reason for hiding this comment

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

I've re-run this many times locally and in CI.

  • Locally, these changes are 1.1x (aXe) to 1.5x (unit) slower, which is barely noticeable
  • In CI however, these changes are 1.3x (aXe) to 1.8x (unit) slower, which is adding ~3.5 minutes to this job. It's still quicker than the visual-diff tests though! 😅

It's admittedly not great, but also not shocking since we're now await-ing all nested Lit components for ~1650 tests, and doing a lot more resetting of the browser state between tests. If the slowness becomes a problem, there's a lot of tests using timeouts that we could look into fixing up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think it's worth doing some cleanup to get a better sense of the real timing

@dlockhart dlockhart marked this pull request as ready for review June 21, 2023 14:10
@dlockhart dlockhart requested a review from a team as a code owner June 21, 2023 14:10
@BrightspaceUI BrightspaceUI deleted a comment from github-actions bot Jun 21, 2023
@@ -21,7 +21,7 @@ jobs:
run: npm run lint:style
playwright:
name: Accessibility and Unit Tests
timeout-minutes: 10
timeout-minutes: 15
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think it's worth doing some cleanup to get a better sense of the real timing

@@ -103,7 +103,7 @@ describe('d2l-input-search', () => {

let clock;
beforeEach(() => {
clock = useFakeTimers();
clock = useFakeTimers({ toFake: ['clearTimeout', 'setTimeout'] });
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be good to note on the eventual README docs

components/list/test/list-item-drag-handle.test.js Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll have to keep an eye on these, to see if one retry tends to be enough. Longer tests make flake that much more painful

@dlockhart dlockhart enabled auto-merge (squash) June 21, 2023 18:30
@dlockhart dlockhart merged commit ffdfcb8 into main Jun 21, 2023
@dlockhart dlockhart deleted the dlockhart/use-brightspace-ui-testing branch June 21, 2023 18:32
@ghost
Copy link

ghost commented Jun 21, 2023

🎉 This PR is included in version 2.131.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants