Files
cypress/system-tests/test/service_worker_spec.js
T
Ryan Manuel c6f5e9a5c9 fix: ensure that we capture service worker requests (#28517)
* fix: ensure that we capture service worker requests

* add changelog

* fix changelog

* fix tests

* PR comments

* PR comments

* PR comment

* PR comment

* update changelog

* Update cli/CHANGELOG.md

Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>

* enable builds on all archs

* fix permission issue

* PR comments

* Update smoke.js

* Update cli/CHANGELOG.md

* attempt to fix smoke tests

* bump ci cache

* Update smoke.js

* Update smoke.js

* Update example.json

* fix multiple specs

* fix tests

* Update CHANGELOG.md

---------

Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>
2024-01-06 15:23:30 -06:00

58 lines
1.4 KiB
JavaScript

const express = require('express')
const Fixtures = require('../lib/fixtures')
const systemTests = require('../lib/system-tests').default
const e2ePath = Fixtures.projectPath('e2e')
let requestsForServiceWorkerCache = 0
const onServer = function (app) {
app.use(express.static(e2ePath, {
// force caching to happen
maxAge: 3600000,
}))
app.get('/service-worker-assets/scope/cached-service-worker', (req, res) => {
res.set({
'Access-Control-Allow-Origin': '*',
})
// redirect to cached-sw-redirect on a cross origin server
return res.redirect('https://localhost:1516/cached-sw-redirect')
})
app.get('/cached-sw-redirect', (req, res) => {
requestsForServiceWorkerCache += 1
res.set({
'Access-Control-Allow-Origin': '*',
})
return res.send('this response will be used by service worker')
})
}
describe('e2e service worker', () => {
systemTests.setup({
servers: [{
https: true,
port: 1515,
onServer,
}, {
https: true,
port: 1516,
onServer,
}],
})
systemTests.it('executes one spec with a cached call', {
project: 'e2e',
spec: 'service_worker.cy.js',
onRun: async (exec, browser) => {
await exec()
// Ensure that we only called this once even though we loaded the
// service worker twice
expect(requestsForServiceWorkerCache).to.eq(1)
},
})
})