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

[core] Allows to run tests with different date adapters #5055

Merged
merged 6 commits into from
Jun 8, 2022

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented May 31, 2022

Allows to test bugs such as #4890 locally for now

to run unit test with a specific adapter, use yarn test:unit --date-adapter moment (or luxon, day-js, date-fns)

@mui-bot
Copy link

mui-bot commented May 31, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 261 717.8 363.1 407.46 162.172
Sort 100k rows ms 519 837 784.5 730.76 113.194
Select 100k rows ms 115.3 207.6 184.8 175.12 31.268
Deselect 100k rows ms 107.1 260 192 181.54 50.133

Generated by 🚫 dangerJS against 236dc9b

@@ -22,7 +22,7 @@ const WrappedDesktopDateTimePicker = withPickerControls(DesktopDateTimePicker)({
describe('<DesktopDateTimePicker />', () => {
const { render } = createPickerRenderer({
clock: 'fake',
clockConfig: adapterToUse.date('2018-01-01T00:00:00.000').getTime(),
clockConfig: new Date('2018-01-01T00:00:00.000'),
Copy link
Member Author

Choose a reason for hiding this comment

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

getTime is a date-fns method (note date-io), so this line was silently bugging when trying to run tests with another library

Copy link
Member

@m4theushw m4theushw Jun 16, 2022

Choose a reason for hiding this comment

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

getTime is a method from Date: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime

Do you know which error you had when using it?

@alexfauquette alexfauquette marked this pull request as ready for review May 31, 2022 14:12
let adapter = 'date-fns';

// Check if we are in unit tests
if (typeof window === 'undefined') {
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
if (typeof window === 'undefined') {
if (/jsdom/.test(window.navigator.userAgent)) {

Should we check for jsdom instead?
When I run yarn test:unit locally, typeof window === 'undefined' returns 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.

Yes, I was looking for a way to distinguish karma and unit 👍

Copy link
Member

Choose a reason for hiding this comment

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

Actually, can we make it work with test:karma as well?
I guess we will have to pass an env variable in karma.conf.js and will complicate things a bit.
What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be nice, but for another PR Could be nice to make test pass with other libraries on master
And before that we should make unit test pass with the current code base which not the case

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 can be addressed in separate PR

And before that we should make unit test pass with the current code base which not the case

You mean to make unit tests pass with each of the adapters?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. For example some tests do not pass because some libraries use uppercase AM/PM and others use am/pm

@alexfauquette alexfauquette merged commit 8623b45 into mui:master Jun 8, 2022
@alexfauquette alexfauquette deleted the testing-libraries branch June 8, 2022 09:12
@m4theushw
Copy link
Member

m4theushw commented Jun 8, 2022

@alexfauquette
Copy link
Member Author

Probably the clockConfig: new Date('2018-01-01T00:00:00.000') that provide different results in Safari

What about using new Date(2018, 0, 1)?

@cherniavskii
Copy link
Member

@alexfauquette let me check it in Safari

@cherniavskii
Copy link
Member

cherniavskii commented Jun 9, 2022

Ok, few observation from me:

  1. I couldn't reproduce the issue locally in Safari 15 (in BrowserStack we use Safari 13). There's no way to install older version of Safari on MacOS, since Webkit is built into OS.
  2. I've tried to run one test locally through BrowserStack Safari and log the start date that we pass to the picker:
    diff --git a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.test.tsx b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.test.tsx
    index 0032283579..fcd8c96333 100644
    --- a/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.test.tsx
    +++ b/packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.test.tsx
    @@ -104,14 +104,14 @@ describe('<DesktopDateRangePicker />', () => {
     
       // TODO: Move to DayPicker test file ?
       describe('selection behavior', () => {
    -    it('should select the range from the next month', () => {
    +    it.only('should select the range from the next month', () => {
           const handleChange = spy();
     
    +      const startDate = adapterToUse.date('2019-01-01T00:00:00.000');
    +      console.log('startDate', startDate);
    +
           render(
    -        <WrappedDesktopDateRangePicker
    -          onChange={handleChange}
    -          initialValue={[adapterToUse.date('2019-01-01T00:00:00.000'), null]}
    -        />,
    +        <WrappedDesktopDateRangePicker onChange={handleChange} initialValue={[startDate, null]} />,
           );
    This resulted in the following output:
    Safari 13.1.2 (Mac OS 10.15.6) WARN: 'including inaccessible elements by default'
      LOG: 'startDate', Tue Jan 01 2019 11:00:00 GMT+1100 (AEDT)
      Safari 13.1.2 (Mac OS 10.15.6) <DesktopDateRangePicker /> selection behavior should select the range from the next month FAILED
              expected '2018-12-31T13:00:00.000Z' to equal '2019-01-01T00:00:00.000Z'
              AssertionError
      
              assertEqual
              methodWrapper
              [native code]
              toEqualDateTime
              methodWrapper
              [native code]
      
      Safari 13.1.2 (Mac OS 10.15.6): Executed 1 of 1438 (1 FAILED) (1.338 secs / 1.308 secs)
    Which shows that the timezone in Safari is AEDT.
  3. I've tried to change timezone on my machine to AEDT and run the same test through BrowserStack Safari, but it resulted in the same output as in 2 above.

I'm not sure why it's failing, but I tend to think it's related to the timezone somehow (maybe related to this? karma-runner/karma-browserstack-launcher#187)
UPDATE: I've run same test on BrowserStack Safari 14(os_version: Big Sur) and tests passed:

Safari 14.1.2 (Mac OS 10.15.7) WARN: 'including inaccessible elements by default'
LOG: 'startDate', Tue Jan 01 2019 00:00:00 GMT+1100 (AEDT)
.
Safari 14.1.2 (Mac OS 10.15.7): Executed 1 of 1438 SUCCESS (1.814 secs / 1.717 secs)

@cherniavskii
Copy link
Member

According to our browserslist we support Safari 14:

safari 14

Same with Supported platforms on MUI website: https://mui.com/material-ui/getting-started/supported-platforms/#browser

Screenshot 2022-06-09 at 13 51 52

So I think it's safe to update Safari version in BrowserStack.

@cherniavskii
Copy link
Member

I've run all test in Safari 14 and some Data Grid tests fail:

Safari 14.1.2 (Mac OS 10.15.7) WARN: 'including inaccessible elements by default'
................................................................................
................................................................................
................................................................................
................................................................................
.........................................
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should call setEditCellValue with the value converted to Date FAILED
        null is not an object (evaluating 'spiedSetEditCellValue.lastCall.args')
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should call setEditCellValue with null when entered an empty value FAILED
        null is not an object (evaluating 'spiedSetEditCellValue.lastCall.args')
.
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should handle correctly dates with partial years FAILED
        null is not an object (evaluating 'spiedSetEditCellValue.lastCall.args')
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should call onValueChange if defined FAILED
        expected +0 to equal 1
        AssertionError

        assertEqual
        methodWrapper
        [native code]

        asyncFunctionResume@[native code]
        [native code]
        promiseReactionJobWithoutPromise@[native code]
        promiseReactionJob@[native code]
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: dateTime should call setEditCellValue with the value converted to Date FAILED
        null is not an object (evaluating 'spiedSetEditCellValue.lastCall.args')
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: dateTime should call setEditCellValue with null when entered an empty value FAILED
        null is not an object (evaluating 'spiedSetEditCellValue.lastCall.args')
.
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: dateTime should handle correctly dates with partial years FAILED
        null is not an object (evaluating 'spiedSetEditCellValue.lastCall.args')
....................
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should call onEditCellPropsChange with the value entered as a Date FAILED
        undefined is not an object (evaluating 'onEditCellPropsChange.args[0][0]')
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should call onEditCellPropsChange with null when entered an empty value FAILED
        undefined is not an object (evaluating 'onEditCellPropsChange.args[0][0]')
..
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should handle all the intermediate dates while editing the value FAILED
        null is not an object (evaluating 'onEditCellPropsChange.lastCall.args')
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: date should call preProcessEditCellProps once if it resolves with an error and preventCommitWhileValidating=true FAILED
        expected 1625407200000 to equal 1641906000000
        AssertionError

        assertEqual
        methodWrapper
        [native code]

        asyncFunctionResume@[native code]
        [native code]
        promiseReactionJobWithoutPromise@[native code]
        promiseReactionJob@[native code]
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: dateTime should call onEditCellPropsChange with the value entered as a Date FAILED
        undefined is not an object (evaluating 'onEditCellPropsChange.args[0][0]')
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: dateTime should call onEditCellPropsChange with null when entered an empty value FAILED
        undefined is not an object (evaluating 'onEditCellPropsChange.args[0][0]')
..
Safari 14.1.2 (Mac OS 10.15.7) <DataGridPro /> - Edit Components column type: dateTime should handle all the intermediate dates while editing the value FAILED
        null is not an object (evaluating 'onEditCellPropsChange.lastCall.args')
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
..........................................
Safari 14.1.2 (Mac OS 10.15.7): Executed 1403 of 1438 (14 FAILED) (skipped 35) (3 mins 30.967 secs / 3 mins 8.414 secs)

@m4theushw
Copy link
Member

We had some problems in the past with BrowserStack using a different locale on Edge: #1665 (comment)

It might be a similar reason here. The date passed to adapterToUse.date doesn't have the timezone. Does it assume GMT?

@cherniavskii
Copy link
Member

We had some problems in the past with BrowserStack using a different locale on Edge: #1665 (comment)

It might be a similar reason here

It looks like it was a Safari issue, since tests that failed in Safari 13 passed in Safari 14 (but other tests started to fail in Safari 14 😀)

alexfauquette added a commit to alexfauquette/mui-x that referenced this pull request Aug 26, 2022
@zannager zannager added core Infrastructure work going on behind the scenes component: pickers This is the name of the generic UI component, not the React module! labels Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants