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.

File watching does not execute actual code changes when site under test utilizes Service Workers.

See original GitHub issue

Related to #686.

It’s possible the application under test ends up using Server Workers to inadvertently cache the files Cypress uses to serve spec files. This prevents changes to the spec files from ever being updated.

Prior to the beginning of all tests we should clear the Service Worker cache and then add a new cy command and add this to lifecycle rules cy.clearServiceWorkerCache().

We could make this command print out all the cache keys it cleared.

Workaround:

before(function () {
  // run this once before all code
  return window.caches.keys().then(function(cacheNames) {
    return Promise.all(
      cacheNames.map(function(cacheName) {
        return window.caches.delete(cacheName);
      })
    );
  })
})

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:20
  • Comments:33 (6 by maintainers)

github_iconTop GitHub Comments

25reactions
abigailcauchicommented, Feb 11, 2019

@mackelito I’ve managed to unregister all service workers before each test in one of my specs like this:

beforeEach(() => {
  if (window.navigator && navigator.serviceWorker) {
    navigator.serviceWorker.getRegistrations()
    .then((registrations) => {
      registrations.forEach((registration) => {
        registration.unregister()
      })
    })
  }
})
18reactions
brian-manncommented, Oct 14, 2017

We need to make a decision here. Currently ServiceWorkers end up generating very confusing behavior in Cypress which is hard for new (and even old) users to debug.

Proposal

  1. Prevent ServiceWorkers from ever being generated by default.
  2. Add two new commands above to enable clearing cache + registrations before each test + after all the tests finish
  3. Add a new config property: enableServiceWorkers: false by default (?)

When we enable lifecycle events this could potentially conflict…

Read more comments on GitHub >

github_iconTop Results From Across the Web

File watching does not execute actual code changes when ...
Within Chrome, go into DevTools > Application > Service Workers and click Unregister . Add the code below for every visit to the...
Read more >
Introduction - Mock Service Worker Docs
Mock Service Worker is an API mocking library that uses Service Worker API to intercept actual requests.
Read more >
Create a Customizable FileSystemWatcher Windows Service
This class is able to detect events in the file system, such as create, modify, or delete files and folders; it's fully customizable;...
Read more >
linux - How to execute a command whenever a file changes?
Simple, using inotifywait (install your distribution's inotify-tools package): while inotifywait -e close_write myfile.py; do ./myfile.py; done.
Read more >
Services overview | Android Developers
A service is simply a component that can run in the background, even when the user is not interacting with your application, so...
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