yyx990803 / register-service-worker

A script to simplify service worker registration with hooks for common events.
MIT License
639 stars 58 forks source link

Error when trying to test service worker logic with vue cli 3 #4

Open matrunchyk opened 6 years ago

matrunchyk commented 6 years ago

Hello, I'm trying to test my SW logic and this is my test spec I'm using:

describe('Service worker', () => {
  it('should delete old caches on activate', async () => {
    const registerSW = require('@/registerServiceWorker');
    console.log(registerSW);
  });
});

And it fails with the following error:

/path/to/myapp/node_modules/register-service-worker/index.js:18
    export function register (swUrl, hooks) {
    ^^^^^^

    SyntaxError: Unexpected token export

How do you do testing of SW using this package?

yyx990803 commented 6 years ago

Hmm, I'm not sure if you actually test that in Jest because your test code is run in Node.js, not in an actual browser. You probably want to test SW using an e2e solution instead.

matrunchyk commented 6 years ago

My plan is to use service-worker-mock to use cases provided in this article.

But it seems to be register-service-worker doesn't allow to do so. Thanks anyway!

lzxb commented 5 years ago

I had the same problem.