Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/ui/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { distClientRoot } from './paths'
export { distClientRoot }

const UI_TOKEN_COOKIE = 'vitest-ui-token'
const UI_TOKEN_COOKIE_MAX_AGE = 60 * 60 * 24 * 365
const AUTH_REQUIRED_MESSAGE = 'Vitest UI requires authentication. Open the URL with the token printed in the terminal, e.g. http://localhost:51204/__vitest__/?token=...'

export default (harness: PluginHarness): Vite.Plugin => {
Expand Down Expand Up @@ -40,6 +41,7 @@ export default (harness: PluginHarness): Vite.Plugin => {
return serializeCookie(UI_TOKEN_COOKIE, ctx.config.api.token, {
path: base,
httpOnly: true,
maxAge: UI_TOKEN_COOKIE_MAX_AGE,
sameSite: 'strict',
})
}
Expand Down
10 changes: 10 additions & 0 deletions test/ui/test/ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ test.describe('ui', () => {
await assertTestCounts(page, { pass: TEST_COUNTS.pass, fail: TEST_COUNTS.fail })
expect(page.url()).toBe(`${cleanPageUrl}#/`)

const tokenCookie = (await page.context().cookies(cleanPageUrl))
.find(cookie => cookie.name === 'vitest-ui-token')
expect(tokenCookie).toMatchObject({
httpOnly: true,
sameSite: 'Strict',
})
expect(tokenCookie!.expires).toBeGreaterThan(
Date.now() / 1000 + 60 * 60 * 24 * 364,
)

await page.goto(cleanPageUrl)
await assertTestCounts(page, { pass: TEST_COUNTS.pass, fail: TEST_COUNTS.fail })
expect(page.url()).toBe(`${cleanPageUrl}#/`)
Expand Down
Loading