-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support usage in cloudflare workers (#27)
- Loading branch information
1 parent
9419819
commit a28051e
Showing
6 changed files
with
1,917 additions
and
2,163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* @jest-environment miniflare | ||
* @jest-environment-options {"scriptPath": "src/index.ts"} | ||
*/ | ||
import { store } from '../src' | ||
|
||
afterEach(() => { | ||
store.clear() | ||
}) | ||
|
||
it('stores cookies for the given request', () => { | ||
const req = new Request('https://mswjs.io') | ||
const res = new Response(null, { | ||
headers: new Headers({ 'Set-Cookie': 'cookieName=abc-123' }), | ||
}) | ||
|
||
store.add(req, res) | ||
|
||
const allCookies = Array.from(store.getAll().entries()) | ||
expect(allCookies).toEqual([ | ||
[ | ||
'https://mswjs.io', | ||
new Map([['cookieName', { name: 'cookieName', value: 'abc-123' }]]), | ||
], | ||
]) | ||
}) | ||
|
||
it('returns cookies for the requests with credentials "include"', () => { | ||
const req = new Request('https://mswjs.io', { | ||
credentials: 'include', | ||
}) | ||
const res = new Response(null, { | ||
headers: new Headers({ 'Set-Cookie': 'secret=abc-123' }), | ||
}) | ||
store.add(req, res) | ||
|
||
const cookies = store.get(req) | ||
expect(cookies).toEqual( | ||
new Map([ | ||
[ | ||
'secret', | ||
{ | ||
name: 'secret', | ||
value: 'abc-123', | ||
maxAge: undefined, | ||
expires: undefined, | ||
}, | ||
], | ||
]), | ||
) | ||
}) | ||
|
||
it('returns cookies for the requests with credentials "same-origin"', () => { | ||
const req = new Request('https://mswjs.io', { | ||
credentials: 'same-origin', | ||
}) | ||
const res = new Response(null, { | ||
headers: new Headers({ 'Set-Cookie': 'secret=abc-123' }), | ||
}) | ||
|
||
store.add(req, res) | ||
store.add( | ||
{ | ||
url: 'https://test.io', | ||
credentials: 'include', | ||
}, | ||
new Response(null, { | ||
headers: new Headers({ 'Set-Cookie': 'anotherCookie=yes' }), | ||
}), | ||
) | ||
|
||
const cookies = store.get(req) | ||
expect(cookies).toEqual( | ||
new Map([['secret', { name: 'secret', value: 'abc-123' }]]), | ||
) | ||
}) | ||
|
||
it('returns cookies for the requests with credentials "omit"', () => { | ||
const req = new Request('https://mswjs.io', { | ||
credentials: 'omit', | ||
}) | ||
const res = new Response(null, { | ||
headers: new Headers({ 'Set-Cookie': 'secret=abc-123' }), | ||
}) | ||
store.add(req, res) | ||
|
||
const cookies = store.get(req) | ||
expect(cookies).toEqual( | ||
new Map([['secret', { name: 'secret', value: 'abc-123' }]]), | ||
) | ||
}) |
Oops, something went wrong.