Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Update Jest@26.6.3, #7418

Closed
wants to merge 3 commits into from
Closed

Update Jest@26.6.3, #7418

wants to merge 3 commits into from

Conversation

tomalec
Copy link
Member

@tomalec tomalec commented Jul 26, 2021

I started this with a hope to address window/jsdom problems encountered in #7378 (comment)
Also, this PR may help with #7218 (comment)

  • Update jest@26.6.3 (from 24.9.0), remove jest-environment-jsdom-sixteen, to somewhat reduce our technical debt.
  • Set timers to legacy as that is what was actually used before. AFAIK jest-environment-jsdom-sixteen was hardcoding it as legacy regardless of config.
  • Update the usage of fake timers
  • Update snapshot of the <Leaderboard> component - I have no idea how and why it passed before. See below.

Accessibility

n/a this PR affects only dev tooling, and updates existing dependencies.

Screenshots

Detailed test instructions:

  1. npm run test

no changelog needed - this changes only dev tooling

remove jest-environment-jsdom-sixteen.
@tomalec tomalec added the type: technical debt This issue/PR represents/solves the technical debt of the project. label Jul 26, 2021
@tomalec
Copy link
Member Author

tomalec commented Jul 26, 2021

There is one failing test:

  ● Leaderboard › should render empty message when there are no rows

    expect(received).toMatchSnapshot()

    Snapshot name: `Leaderboard should render empty message when there are no rows 1`

    - Snapshot  - 1
    + Received  + 0

    @@ -13,11 +13,10 @@
          <div
            class="components-card__body css-xmjzce-BodyUI e1q7k77g3"
          >
            <div
              class="woocommerce-table is-empty"
    -         style="--number-of-rows: 5;"

But, AFAI Can Tell it should fail, as there is no reason why <EmptyTable> should have 5 rows. There is no such prop being passed:
https://github.com/woocommerce/woocommerce-admin/blob/main/client/analytics/components/leaderboard/index.js#L80

I have no idea how and why this test passed before.

@tomalec
Copy link
Member Author

tomalec commented Jul 26, 2021

BTW, I don't know why we use toMatchSnapshot everywhere, instead of actually testing what the test description states? It breaks test atomicity, making them extremely fragile and hard to maintain.

IMO, we should write something like:

test( 'should render empty message when there are no rows', () => {
	  // ...
	  
	  expect( leaderboard ).to.contain( 'EmptyTable' )
	  expect( leaderboard ).to.have.rendered.text( 'No data recorded for the selected time period' );
} );

@tomalec tomalec self-assigned this Jul 26, 2021
There is no reason why <EmptyTable> should have 5 rows. There is no such prop being passed.
@louwie17
Copy link
Contributor

@tomalec just a heads up in relation to this PR (given it is still in draft). The reason we are still using 24.9 is because of a pretty big performance issue in newer versions of Jest. See this original PR and this Jest issue which is still open 😢

If you do go ahead with this, it would be great to get some info on the performance difference, is it still relevant or not? (We might even want to try Jest 27 now).

@tomalec tomalec mentioned this pull request Jul 26, 2021
2 tasks
@samueljseay
Copy link
Contributor

samueljseay commented Jul 27, 2021

@tomalec @louwie17 I tried jest 27 lately its a lot faster, but I had trouble getting some tests working.

@tomalec Also I'm happy to delete the failing snapshot test. I encouraged the team to stop writing snapshot tests because of what you say which is they're basically useless for testing anything (and very fragile). If its possible to write a corresponding basic test for the removed snapshot one then great, but I wouldn't block on that either.

@tomalec
Copy link
Member Author

tomalec commented Jul 27, 2021

Thanks for all the info :) Given my local env problems related to #7378 are now solved (react-test-renderer + node@14) I'll try to jump to a higher version that does not degrade the performance. Hopefully by the end of this week / some time off next week.

@psealock
Copy link
Collaborator

I'll close this in favor of #7430 which update to version 27. Thank you @tomalec for getting this effort underway!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tool: monorepo infrastructure type: technical debt This issue/PR represents/solves the technical debt of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants