forked from valeriangalliat/fetch-cookie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
51 lines (40 loc) · 1.29 KB
/
test.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
42
43
44
45
46
47
48
49
50
51
/* eslint-env mocha */
const { equal } = require('assert')
const express = require('express')
const nodeFetch = require('node-fetch')
const fetch = require('./')(nodeFetch)
const app = express()
app.get('/set', (req, res) => {
res.set('set-cookie', 'foo=bar')
res.end()
})
app.get('/set2', (req, res) => {
res.set('set-cookie', 'foo=bar2')
res.end()
})
app.get('/get', (req, res) => {
res.end(req.headers.cookie)
})
app.get('/redirect', (req, res) => {
res.redirect('http://localhost:9998/get')
})
app.listen(9999)
describe('fetch-cookie', () => {
it('should handle cookies', async () => {
await fetch('http://localhost:9999/set');
const res = await fetch('http://localhost:9999/get');
equal(await res.text(), 'foo=bar');
})
it('should handle cookies jars', async () => {
const cookieJar1 = {};
const cookieJar2 = {};
await fetch('http://localhost:9999/set', cookieJar1);
const res1 = await fetch('http://localhost:9999/get', cookieJar1);
await fetch('http://localhost:9999/set2', cookieJar2);
const res2 = await fetch('http://localhost:9999/get', cookieJar2);
equal(await res1.text(), 'foo=bar');
equal(cookieJar1.headers.cookie, 'foo=bar');
equal(await res2.text(), 'foo=bar2');
equal(cookieJar2.headers.cookie, 'foo=bar2');
})
})