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

[ETK] Update @wordpress/interface to the latest published version #73629

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ logFilters:
pattern: "@automattic/global-styles@workspace:packages/global-styles provides react-dom (*) with version 17.0.2, which doesn't satisfy what @wordpress/block-editor and some of its descendants request"
- level: discard
pattern: "@automattic/global-styles@workspace:packages/global-styles provides react-dom (*) with version 17.0.2, which doesn't satisfy what @wordpress/components and some of its descendants request"
- level: discard
pattern: "@automattic/wpcom-editing-toolkit@workspace:apps/editing-toolkit provides react (p3131a) with version 17.0.2, which doesn't satisfy what @wordpress/interface and some of its descendants request"
- level: discard
pattern: "@automattic/wpcom-editing-toolkit@workspace:apps/editing-toolkit provides react-dom (pd5894) with version 17.0.2, which doesn't satisfy what @wordpress/interface and some of its descendants request"

nodeLinker: node-modules

Expand Down
2 changes: 1 addition & 1 deletion apps/editing-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"@wordpress/html-entities": "^3.9.0",
"@wordpress/i18n": "^4.9.0",
"@wordpress/icons": "^9.0.0",
"@wordpress/interface": "^4.8.0",
"@wordpress/interface": "^5.4.0",
"@wordpress/is-shallow-equal": "^4.9.0",
"@wordpress/keycodes": "^3.9.0",
"@wordpress/notices": "^3.10.0",
Expand Down
12 changes: 10 additions & 2 deletions client/blocks/time-mismatch-warning/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ jest.mock( 'calypso/state/preferences/selectors', () => ( {
getPreference: jest.fn( () => false ),
} ) );

class MockedDate extends Date {
getTimezoneOffset() {
return 240;
}
}

const originalDate = global.Date;

describe( 'TimeMismatchWarning', () => {
beforeAll( () => {
jest.spyOn( global, 'Date' ).mockImplementation( () => ( { getTimezoneOffset: () => 240 } ) );
global.Date = MockedDate;
Copy link
Contributor Author

@fullofcaffeine fullofcaffeine Feb 22, 2023

Choose a reason for hiding this comment

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

These tests were failing with:

   TypeError: Date.now is not a function                                                                                                                                                                           
                                                                                                                                                                                                                    
      at ../node_modules/requestidlecallback/index.js:57:21                                                                                                                                                         
      at MutationObserver.onInputorMutation (../node_modules/requestidlecallback/index.js:87:3)   

I haven't dug too deep, but looks like this is caused by the requestidlecallback package, which now uses Date.now . Before the package updates that are part of this PR, Date.now was not in any of the code paths for this test (apparently), so something changed after the update.

With the mockedImplementation approach, it discarded Date's original implementation to only define the custom getTimezoneOffset. I've tried to use spyOn + mockImplementation to return a custom class based off Date but failed - it was much simpler to just override the global variable and re-assign the original object to it in the afterAll callback.

I wonder why this test triggered a portion of code that uses this package now while it didn't before the update. Maybe that package was already used, and it was recently updated to use Date.now. Provided tests pass, I think it's okay to consider this relatively safe to ship, but if you have more insights, let me know. Besides, in the case of globals like Date, I think it's safer to keep the original implementation accessible and mock the functions over it. The previous approach based on mockImplementation removed all other functions and properties (including the static now).

Copy link
Member

Choose a reason for hiding this comment

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

No concerns from my side about this change. We've seen similar issues in Gutenberg tests too. It's usually that something tries to access Date before the jsdom mock has been setup, or something inadvertently overrides it for the test.

} );

afterAll( () => {
jest.spyOn( global, 'Date' ).mockRestore();
global.Date = originalDate;
} );

test( 'to render nothing if no site ID is provided', () => {
Expand Down
Loading