Skip to content

Commit

Permalink
test: create unit tests to ensure the issue does not occur again
Browse files Browse the repository at this point in the history
  • Loading branch information
vermaysha committed Jun 4, 2024
1 parent f5c1776 commit aee4421
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('Content-Encoding')).toBeNull()
expect(res.headers.get('vary')).toBeNull()
})

it('handle brotli compression', async () => {
Expand All @@ -45,6 +46,7 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('Content-Encoding')).toBe('br')
expect(res.headers.get('vary')).toBe('accept-encoding')
})

it('handle deflate compression', async () => {
Expand All @@ -54,6 +56,7 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('Content-Encoding')).toBe('deflate')
expect(res.headers.get('vary')).toBe('accept-encoding')
})

it('handle gzip compression', async () => {
Expand All @@ -63,6 +66,7 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('Content-Encoding')).toBe('gzip')
expect(res.headers.get('vary')).toBe('accept-encoding')
})

it('accept additional headers', async () => {
Expand All @@ -77,6 +81,7 @@ describe('Compression With Elysia', () => {

expect(res.headers.get('Content-Encoding')).toBe('deflate')
expect(res.headers.get('x-powered-by')).toBe('Elysia')
expect(res.headers.get('vary')).toBe('accept-encoding')
})

it('return correct plain/text', async () => {
Expand All @@ -87,6 +92,7 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('Content-Type')).toBe('text/plain')
expect(res.headers.get('vary')).toBe('accept-encoding')
})

it('return correct application/json', async () => {
Expand All @@ -99,6 +105,7 @@ describe('Compression With Elysia', () => {
expect(res.headers.get('Content-Type')).toBe(
'application/json;charset=utf-8',
)
expect(res.headers.get('vary')).toBe('accept-encoding')
})

it('return correct image type', async () => {
Expand All @@ -109,6 +116,7 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('Content-Type')).toBe('image/png')
expect(res.headers.get('vary')).toBeNull()
})

it('must be redirected to /not-found', async () => {
Expand Down Expand Up @@ -154,6 +162,7 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('Content-Encoding')).toBe('gzip')
expect(res.headers.get('vary')).toBe('accept-encoding')
})

it('cors should be enable when threshold 1024', async () => {
Expand Down Expand Up @@ -202,5 +211,6 @@ describe('Compression With Elysia', () => {
const res = await app.handle(req())

expect(res.headers.get('access-control-allow-origin')).toBe('*')
expect(res.headers.get('vary')).toBe('*')
})
})

0 comments on commit aee4421

Please sign in to comment.