Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Fix flaky mobile registration tests #102

Merged
merged 3 commits into from
Sep 30, 2024
Merged

Fix flaky mobile registration tests #102

merged 3 commits into from
Sep 30, 2024

Conversation

t3chguy
Copy link
Member

@t3chguy t3chguy commented Sep 30, 2024

Signed-off-by: Michael Telatynski <[email protected]>
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

I'm very happy to see a fix to this flake, but can you talk me through how this helps?

@t3chguy
Copy link
Member Author

t3chguy commented Sep 30, 2024

The JSDom CSSDeclaration stuff doesn't behave exactly the same as it does in browsers. Namely the object has a bunch of extra fields which don't match the types we come to expect from the signature, so changing the way we iterate it fixes that. There was then another flake where we're rendering MatrixChat without the bits of element-web's index.html which set up styles which caused a race condition with the ThemeWatcher firing off other bits of theming code which were unhappy to be missing the theme bits in index.html

@@ -60,6 +60,7 @@ import { UIFeature } from "../../../src/settings/UIFeature";
jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({
completeAuthorizationCodeGrant: jest.fn(),
}));
jest.mock("../../../src/settings/watchers/ThemeWatcher");
Copy link
Member

Choose a reason for hiding this comment

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

There was then another flake where we're rendering MatrixChat without the bits of element-web's index.html which set up styles which caused a race condition with the ThemeWatcher firing off other bits of theming code which were unhappy to be missing the theme bits in index.html

maybe add a comment here to explain that, and say we're disabling ThemeWatcher?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

src/theme.ts Outdated
Comment on lines 116 to 117
for (let i = 0; i < document.body.style.length; i++) {
const prop = document.body.style[i];
Copy link
Member

@richvdh richvdh Sep 30, 2024

Choose a reason for hiding this comment

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

The JSDom CSSDeclaration stuff doesn't behave exactly the same as it does in browsers. Namely the object

"the object" here being document.body.style ? Which is supposed to be a CSSStyleDeclaration but maybe isn't?

has a bunch of extra fields which don't match the types we come to expect from the signature, so changing the way we iterate it fixes that.

Ok, but:

  • why was it intermittent?
  • Again, a comment here explaining that we're working around jsdom weirdness would be good. The first thing I want to do when I see this code is refactor it to for (const prop of document.body.style) { ... }, which for any normal array-like-object would be identical.

Copy link
Member Author

Choose a reason for hiding this comment

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

why was it intermittent?

Race condition between the test & ThemeWatcher

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 part was inherently just defensive against JSDom but should be superfluous given the stubbing out of ThemeWatcher

@t3chguy t3chguy added this pull request to the merge queue Sep 30, 2024
Merged via the queue into develop with commit fe402e2 Sep 30, 2024
27 checks passed
@t3chguy t3chguy deleted the t3chguy/fix/28122 branch September 30, 2024 16:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky jest test: <MatrixChat /> › mobile registration › should render mobile registration
2 participants