swae
v0.0.27
Published
A service worker testing framework
Downloads
34
Readme
swae
ServiceWorkerAssessmentEngine
A service worker testing framework in the early stages of development. There are lots of bugs, and every release is potentially a breaking change. Effectively a big wrapper around chrome-debugging-client, which is node client for interacting with Headless Chrome via the Chrome DevTools Protocol. Built with TypeScript.
Example
import { expect } from 'chai';
import { TestSession } from 'swae';
import { createServer } from './my-test-server';
const session = new TestSession(createServer());
before(session.ready.bind(session));
after(session.close.bind(session));
describe('Service Worker', () => {
it('should respond to requests', async () => {
await session.run(async (testEnv) => {
const client = await testEnv.createTab();
await client.navigate();
await client.evaluate(function() {
return navigator.serviceWorker.register('/sw.js');
});
await client.swState.waitForActivated();
const { body, networkResult } = await client.navigate();
expect(networkResult.response.fromServiceWorker).to.be.true;
});
});
});