stream-to-sw
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "stream-to-sw", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "intercept fetch requests with a service worker, but process the response on the main thread", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
16
test.js
@@ -27,5 +27,3 @@ const test = require('muggle-test') | ||
const readyPromise = registerStreamToSw('./testWorker.js', async (req, res) => { | ||
const path = req.url.replace(window.origin, '') | ||
switch (path) { | ||
switch (req.path) { | ||
case '/test/penguin': { | ||
@@ -59,2 +57,5 @@ return 'penguin' | ||
} | ||
case '/test/reqPath': { | ||
return req.path | ||
} | ||
case '/test/requestBody': { | ||
@@ -157,2 +158,11 @@ const body = await new window.Response(req.body).text() | ||
test('request.path should be set correctly', async () => { | ||
await readyPromise | ||
const plainPathResponse = await window.fetch('/test/reqPath?param=true#hash') | ||
const plainPath = await plainPathResponse.text() | ||
assert.equal(plainPath, '/test/reqPath', 'path should strip origin, query params, and hash') | ||
}) | ||
test('body should be passed into the Req object', async () => { | ||
@@ -159,0 +169,0 @@ await readyPromise |
@@ -45,3 +45,3 @@ /* eslint-env serviceworker */ | ||
path = path.replace(/#.*$/, '') // trim hash | ||
path = path.replace(/\?.*$/) // trim query params | ||
path = path.replace(/\?.*$/, '') // trim query params | ||
path = path.replace(/\/$/, '') // trim trailing slash if present | ||
@@ -48,0 +48,0 @@ |
26116
460