FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(material/core): sanity checks not disabled for node-based test environments by crisbeto · Pull Request #23636 · angular/components · GitHub

fix(material/core): sanity checks not disabled for node-based test environments - #23636

Merged
mmalerba merged 1 commit into
angular:masterfrom
crisbeto:23365/sanity-checks-test-again
Sep 30, 2021
Merged

fix(material/core): sanity checks not disabled for node-based test environments#23636
mmalerba merged 1 commit into
angular:masterfrom
crisbeto:23365/sanity-checks-test-again

Conversation

Copy link
Copy Markdown
Member

In #23374 we expanded the logic that checks for test environments to cover Jest and Mocha. The problem is that we were checking against the window which won't work in a Node environment, because the global variables are attached to the global object, not the window, even though there may be a fake window declared by the test tooling.

These changes resolve the issue by first checking against global before falling back to window.

Fixes #23365.

crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release labels Sep 24, 2021
crisbeto requested a review from jelbourn September 24, 2021 15:56
google-cla Bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 24, 2021

devversion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

crisbeto force-pushed the 23365/sanity-checks-test-again branch from 8e20836 to 81e467d Compare September 24, 2021 16:01
crisbeto requested a review from a team September 24, 2021 16:01
crisbeto force-pushed the 23365/sanity-checks-test-again branch from 81e467d to be6774f Compare September 24, 2021 16:12

/** The timeout id of the window focus timeout. */
private _windowFocusTimeoutId: number;
private _windowFocusTimeoutId: any;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

These are necessary, because the type now is number | NodeJS.Timer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hmm. looks like these any casts are just needed for the legacy Saucelabs setup. Should we instead just declare the global type directly instead? I think that would be better than giving up on type safety. e.g.

declare const global: any;

crisbeto Sep 24, 2021
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There's a comment at the top of that file about avoiding declare const due to an issue with Closure so that's why I wrote it this way in the first place. Otherwise the same could've been written as declare cost jest: any.

devversion Sep 24, 2021
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

oh that's unfortunate. What is about globalThis? this should work as well and not need any Node types. Seems like it's ideal for such platform-agnostic checks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I avoided it since it isn't supported in some browsers (not sure if we care about them) and the workaround wasn't that much more code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

okay, I don't feel very strongly about it. It seems supported by all of the browsers we make guarantees for (https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/globalThis), and it would save us from using any in all of cdk/ (for the timers).

crisbeto force-pushed the 23365/sanity-checks-test-again branch from be6774f to 100028e Compare September 24, 2021 16:14
…vironments

In angular#23374 we expanded the logic that checks for test environments to cover Jest and Mocha. The problem is that we were checking against the `window` which won't work in a Node environment, because the global variables are attached to the `global` object, not the `window`, even though there may be a fake `window` declared by the test tooling.

These changes resolve the issue by first checking against `global` before falling back to `window`.

Fixes angular#23365.
crisbeto force-pushed the 23365/sanity-checks-test-again branch from 100028e to 52cba8d Compare September 24, 2021 18:05
crisbeto added the action: merge The PR is ready for merge by the caretaker label Sep 24, 2021
josephperrott removed the request for review from a team September 27, 2021 16:22

Copy link
Copy Markdown

Thanks for the follow-through on this.

mmalerba merged commit 4f6b9fd into angular:master Sep 30, 2021
mmalerba pushed a commit that referenced this pull request Sep 30, 2021
…vironments (#23636)

In #23374 we expanded the logic that checks for test environments to cover Jest and Mocha. The problem is that we were checking against the `window` which won't work in a Node environment, because the global variables are attached to the `global` object, not the `window`, even though there may be a fake `window` declared by the test tooling.

These changes resolve the issue by first checking against `global` before falling back to `window`.

Fixes #23365.

(cherry picked from commit 4f6b9fd)
crisbeto added a commit to crisbeto/material2 that referenced this pull request Oct 10, 2021
In angular#23636 the test environment check was changed so that it looks for the test objects either on `window` or `global`, however it looks like this isn't enough to pick up Jest which isn't published on either.

These changes simplify the setup by looking up the value globally and disabling the type checkng error with `@ts-ignore`. We can't use `declare const` for it, because it causes issues in g3.

I've also reverted some of the `any` types that had to be added in angular#23636.

Fixes angular#23365.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Oct 10, 2021
In angular#23636 the test environment check was changed so that it looks for the test objects either on `window` or `global`, however it looks like this isn't enough to pick up Jest which isn't published on either.

These changes simplify the setup by looking up the value globally and disabling the type checkng error with `@ts-ignore`. We can't use `declare const` for it, because it causes issues in g3.

I've also reverted some of the `any` types that had to be added in angular#23636.

Fixes angular#23365.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Oct 25, 2021
In angular#23636 the test environment check was changed so that it looks for the test objects either on `window` or `global`, however it looks like this isn't enough to pick up Jest which isn't published on either.

These changes simplify the setup by looking up the value globally and disabling the type checkng error with `@ts-ignore`. We can't use `declare const` for it, because it causes issues in g3.

I've also reverted some of the `any` types that had to be added in angular#23636.

Fixes angular#23365.

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

angular-automatic-lock-bot Bot locked and limited conversation to collaborators Oct 31, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Sanity checks run in test environement

4 participants


Back | FazBrowse Home | New Git URL