-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathservice_worker_spec.js
More file actions
59 lines (50 loc) · 1.43 KB
/
service_worker_spec.js
File metadata and controls
59 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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',
retries: 10,
onRun: async (exec, browser) => {
requestsForServiceWorkerCache = 0
await exec()
// Ensure that we only called this once even though we loaded the
// service worker twice
expect(requestsForServiceWorkerCache).to.eq(1)
},
})
})