question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mocks fail intermittently when multiple browser tabs are open

See original GitHub issue

Describe the bug

The mocks fail intermittently when multiple browser tabs are open

Environment

  • msw: 0.15.5
  • nodejs: 10.19.0
  • react: 16.13.1
  • react-scripts: 3.4.1 // create-react-app

Please also provide your browser version. Chrome 81.0.4044.113 (Official Build) (64-bit) Linux - Ubuntu

To Reproduce

  • Have set up update on reload for the service worker
  • Have multiple browser tabs open, eg:
    • http://localhots:3000/
    • http://localhost:3000/episode/Fz9eb58992-1e0f-4b2a-ac69-37fce2e934df?section=Storylines
  • Have MSW setup with following options:
const options = { serviceWorker: { url: '/mockServiceWorker.js' } }
  • Have the following MSW rule:
export default [
    rest.get(
        `https://example.com/lists/characters/:rdfID`,
        (_req, res, { json }) => {
            return res(json(characters))
        },
    ),
]

const characters: Character[] = [
    {
        characterId: 'z9540c2f4-0970-de63-9973-ae9cb4ac31b8',
        characterName: 'Pinkie Pie',
    },
    {
        characterId: 'z67416fa2-6883-4c1f-2db9-012984486da6',
        characterName: "Rarity",
    },
]
  • Refresh http://localhost:3000/episode/Fz9eb58992-1e0f-4b2a-ac69-37fce2e934df?section=Storylines

Expected behavior

https://example.com/list/characters/Fz9eb58992-1e0f-4b2a-ac69-37fce2e934df Should be mocked, but randomly it’s not.

Workaround

Close all browser tabs but one. This fixes the issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
kettanaitocommented, May 12, 2020

@VanTanev, thanks for such a detailed debugging and great lead! Happy to hear it works.

2reactions
VanTanevcommented, May 12, 2020

@kettanaito It seems to work, thank you for your work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Flaky Tests - Semaphore CI
Randomly failing tests are the hardest to debug. Here's a framework you can use to fix them and keep your test suite healthy....
Read more >
Too many browser tabs open - Microsoft Community
I am having slow and freezing problems with edge and firefox browsers. I started opening task manager and checking the browsers.
Read more >
Why did my test fail? - Testim overview
Tab not Found. This error occurs when Testim could not find the correct tab for the step to act on. Common Causes: Test...
Read more >
Chrome tabs intermittent hang or crash with white screen
An immediate fix to the failed tabs can be to restart the browser, however, after a significant wait, they will regain functionality. Our...
Read more >
Why tests pass locally but fail in Jenkins | Object Partners
I've seen this occur when the test assertions are actually completed before the async calls finish. If possible, you should run your assertions ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found