also looking at this
Close unauthenticated /api/requests CRUD, and make the session cookie HttpOnly
#77
11 files
+552
-57
| @@ -1,4 +1,29 @@ | ||
| 1 | import { expect, test } from 'bun:test' | |
| 1 | import { afterAll, beforeAll, expect, test } from 'bun:test' | |
| 2 | import { GlobalRegistrator } from '@happy-dom/global-registrator' | |
| 3 | ||
| 4 | /** | |
| 5 | * DOM-dependent tests. | |
| 6 | * | |
| 7 | * The DOM is registered HERE rather than in `tests/setup.ts`, because | |
| 8 | * `GlobalRegistrator.register()` swaps `Request`/`Response`/`Headers` for | |
| 9 | * happy-dom's browser implementations, and a browser `Headers` silently drops | |
| 10 | * `Set-Cookie` and `Cookie` (the Fetch spec calls them forbidden header names). | |
| 11 | * Registering it globally therefore made `tests/unit/session-cookie.test.ts` | |
| 12 | * unable to see the `HttpOnly` session cookie it exists to assert. See | |
| 13 | * `tests/setup.ts` for the measurement. | |
| 14 | * | |
| 15 | * Bun runs test files in one process, so the registration is bracketed: any | |
| 16 | * file that needs a DOM takes it for its own duration and hands the native | |
| 17 | * globals back afterwards, instead of mutating the whole run. | |
| 18 | */ | |
| 19 | ||
| 20 | beforeAll(() => { | |
| 21 | GlobalRegistrator.register() | |
| 22 | }) | |
| 23 | ||
| 24 | afterAll(async () => { | |
| 25 | await GlobalRegistrator.unregister() | |
| 26 | }) | |
| 2 | 27 | |
| 3 | 28 | test('dom test', () => { |
| 4 | 29 | document.body.innerHTML = `<button>My button</button>` |