-
Notifications
You must be signed in to change notification settings - Fork 607
/
Copy pathinitator.js
41 lines (31 loc) · 1.12 KB
/
initator.js
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
'use strict'
const { test, describe, before, after } = require('node:test')
const assert = require('node:assert')
const events = require('node:events')
const http = require('node:http')
const { fetch, Request } = require('../../')
const { closeServerAsPromise } = require('../utils/node-http')
describe('initiator', () => {
const server = http.createServer((req, res) => {
res.end(req.headers['sec-purpose'])
})
before(async () => {
server.listen(0)
await events.once(server, 'listening')
})
after(closeServerAsPromise(server))
test('if initiator is not "prefetch" then sec-purpose is not set', async (t) => {
const url = `http://localhost:${server.address().port}`
const response = await fetch(url, {
initiator: ''
})
assert.strictEqual(await response.text(), '')
})
test('if initiator is set to prefetch then the sec-purpose header is set to "prefetch"', async (t) => {
const url = `http://localhost:${server.address().port}`
const response = await fetch(new Request(url, {
initiator: 'prefetch'
}))
assert.deepStrictEqual(await response.text(), 'prefetch')
})
})