-
Notifications
You must be signed in to change notification settings - Fork 146
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
Upgrade msw to latest #1100
Upgrade msw to latest #1100
Conversation
My guess of why there was an error is that there's nothing left to wait for. Perhaps jest already shuts down the test, while react-testing-library is waiting to see more. Other people out there have experienced the same error: testing-library/react-testing-library#1027 (comment)
Not sure why it seems to be timing out. And different results when only that single test is run vs running the whole test file.
@@ -61,7 +61,7 @@ | |||
"jsonwebtoken": "^9.0.0", | |||
"jwt-decode": "^3.1.2", | |||
"lodash": "^4.17.21", | |||
"msw": "^0.28.1", | |||
"msw": "^1.2.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context: v0.x was up to 0.49, whereas we were on 0.28. So we were behind by a lot.
// Let's not close the server and see how things goes. | ||
// We can revisit this. | ||
// global.server.close() | ||
global.server.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I see, bringing it back does not seem to affect anything. But it was the recommended way by msw documentation.
// Otherwise, the test would end prematurely before our component has finished its business | ||
// (for example: commerce-sdk-react Provider needs to finish its useEffect for `auth.ready()`) | ||
await waitFor(() => { | ||
expect(window.localStorage.setItem).toHaveBeenCalled() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally this AppConfig test is fixed 😌 Previously it failed every time on my machine, and it was failing intermittently on CI.
expect(within(summary).getAllByText(/61.43/i).length).toEqual(2) | ||
|
||
expect(screen.getByTestId('sf-cart-skeleton')).toBeInTheDocument() | ||
expect(screen.queryByTestId('sf-cart-container')).not.toBeInTheDocument() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified this test by checking for the skeletons only. Checking for the other things has already been done by the other tests in this file.
@@ -293,15 +286,33 @@ describe('Remove item from cart', function () { | |||
) | |||
}) | |||
test('Can remove item from the cart', async () => { | |||
if (process.env.CI) { | |||
console.log('--- skipping this test only in CI because it has proven to be flaky there') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cart test is annoyingly flaky. I couldn't figure out why a simple findBy
query can lead to a timeout. Have tried various things.
Anyways, I decided to conditionally skip this test if it runs on CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather we just test.skip
it than execute it conditionally on CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll skip the test.
beforeEach(() => { | ||
global.server.use( | ||
rest.get('*/orders/:orderId', (req, res, ctx) => { | ||
return res(ctx.delay(0), ctx.json(mockOrder)) | ||
}), | ||
rest.get('*/products', (req, res, ctx) => { | ||
return res(ctx.delay(0), ctx.json(mockProducts)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We forgot to mock this endpoint. Now it is there.
const [selectedAddressId, setSelectedAddressId] = useState(false) | ||
const hasSavedAddresses = customer.addresses?.length > 0 | ||
const [isEditingAddress, setIsEditingAddress] = useState(false) | ||
const [selectedAddressId, setSelectedAddressId] = useState(undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file are to address the scenario when the current customer data is not fully available yet. This scenario leads to an intermittent bug that I've logged in GUS ticket W-12779702.
Previously it was hard to reproduce the bug locally. But now the checkout tests can reproduce it consistently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one minor comment, not blocking but I think differing test runs between CI and local test runs is a "slippery slope"
@@ -105,11 +105,12 @@ const ShippingAddressSelection = ({ | |||
onSubmit = async () => null | |||
}) => { | |||
const {formatMessage} = useIntl() | |||
const {data: customer} = useCurrentCustomer() | |||
const {data: customer, isLoading, isFetching} = useCurrentCustomer() | |||
const isLoadingRegisteredCustomer = isLoading && isFetching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this look like we are looking for isInitialLoading? https://tanstack.com/query/v4/docs/react/guides/disabling-queries#isinitialloading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it's the same as isInitialLoading
. Forgot about that.
In the normal cases, I would switch to isInitialLoading
. But with useCurrentCustomer
, I feel that it does not really represent what really happens. The query is enabled only if the customer is registered. So it's clearer to me if I name it isLoadingRegisteredCustomer
.
@@ -292,16 +285,30 @@ describe('Remove item from cart', function () { | |||
}) | |||
) | |||
}) | |||
test('Can remove item from the cart', async () => { | |||
test.skip('Can remove item from the cart', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per Brian's comment, I decided to skip this test: #1100 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for helping improve our testing @vmarta 💪 🏅
LGTM
* v3: [Spike]Replace watch with nodemon (#1146) Fix Page Designer ImageWithText Link component (#1092) (#1148) Upgrade deprecated dependencies (#1124) Restart login flow if refresh_token is invalid (#1135) Move some util to site-utils to avoid circular imports (#1133) Restore old file name. (#1140) Update eslint configuration (#1129) CI: clarify the environment variables (#1127) Remove react-query-devtools from production build (#1121) Update lerna.json (#1118) Parallelize lighthouse ci (#1126) Increase test timeouts only on CI env (#1123) Remove unused `request` deprecated dependency. (#1125) Upgrade msw to latest (#1100) Add mergeBasket hook (#1114) [V3][Hooks Integration 🪝] Manually update cache for ShopperCustomer (#1113) dont use callback on mutateAsync (#1119) 2-spaces not 4-spaces (#1117) # Conflicts: # packages/internal-lib-build/package-lock.json # packages/pwa-kit-create-app/package-lock.json # packages/pwa-kit-dev/package-lock.json # packages/pwa-kit-dev/package.json # packages/pwa-kit-dev/src/configs/webpack/config.js # packages/pwa-kit-dev/src/ssr/server/build-dev-server.js # packages/pwa-kit-react-sdk/package-lock.json # packages/pwa-kit-runtime/package-lock.json # packages/template-express-minimal/package-lock.json # packages/template-mrt-reference-app/package-lock.json # packages/template-retail-react-app/package-lock.json # packages/template-typescript-minimal/package-lock.json # packages/test-commerce-sdk-react/package-lock.json
…-rehaul * feature/template-extensibility: [Spike]Replace watch with nodemon (#1146) Fix Page Designer ImageWithText Link component (#1092) (#1148) Upgrade deprecated dependencies (#1124) Restart login flow if refresh_token is invalid (#1135) Move some util to site-utils to avoid circular imports (#1133) Restore old file name. (#1140) Update eslint configuration (#1129) CI: clarify the environment variables (#1127) Remove react-query-devtools from production build (#1121) Update lerna.json (#1118) Parallelize lighthouse ci (#1126) Increase test timeouts only on CI env (#1123) Remove unused `request` deprecated dependency. (#1125) Upgrade msw to latest (#1100) Add mergeBasket hook (#1114) [V3][Hooks Integration 🪝] Manually update cache for ShopperCustomer (#1113) dont use callback on mutateAsync (#1119) 2-spaces not 4-spaces (#1117) # Conflicts: # packages/internal-lib-build/package-lock.json # packages/pwa-kit-dev/package-lock.json # packages/pwa-kit-react-sdk/package-lock.json # packages/pwa-kit-runtime/package-lock.json # packages/pwa-kit-runtime/package.json
This PR does 2 main things:
msw
to the next major version v1 ← 5% of the work.. it was quite straightforward, thankfully.The only breaking change with msw v1 does not affect us because retail-react-app does not use those types in Typescript.
Another good thing is that some tests that were intermittently failing fail consistently now across CI and locally. So it’s now easier to reproduce the issues and debug them. For example, the AppConfig test with its error "Test suite failed to run. Call retries were exceeded".
Types of Changes
Changes
How to Test-Drive This PR
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization