Skip to content

Commit

Permalink
test: add some util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Aug 16, 2024
1 parent 0d2a256 commit e6e84f0
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/unit/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {describe, test, expect} from 'vitest'

import {
createTimings,
combineServerTimingHeaders
} from '~/lib/utils/timings.server'

import {pageTitle} from '~/lib/utils/page-title'

describe('Timing', () => {
test('should create timings', async () => {
const {time, headers} = createTimings()

await time('runTest', 'Run Test', async () => {
return true
})

const timingHeaders = headers()

expect(timingHeaders['Server-Timing']).toMatch(/runTest/)

const timings2 = createTimings()

await timings2.time('test2', 'Test Two', async () => {
return true
})

const timing2Headers = timings2.headers()

expect(timing2Headers['Server-Timing']).toMatch(/test2/)

const combinedHeaders = combineServerTimingHeaders(
new Headers(timingHeaders),
new Headers(timing2Headers)
)

const combined = combinedHeaders.get('Server-Timing')

expect(combined).toMatch(/runTest/)
expect(combined).toMatch(/test2/)

const combined2 = combineServerTimingHeaders(
new Headers(timingHeaders),
new Headers()
).get('Server-Timing')

expect(combined2).toMatch(/runTest/)
expect(combined2).not.toMatch(/test2/)
})
})

describe('Page Title', () => {
test('should generate a page title', () => {
expect(pageTitle('Test')).toBe('Net Doc / Test')
})
})

0 comments on commit e6e84f0

Please sign in to comment.