-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #68 not working with static plugin #130
base: master
Are you sure you want to change the base?
Changes from all commits
623f996
440e9d3
a57a3a8
50faa84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { describe, expect, it } from 'bun:test' | ||
import zlib from 'node:zlib' | ||
import Elysia from 'elysia' | ||
import staticPlugin from '@elysiajs/static' | ||
import { Stream } from '@elysiajs/stream' | ||
import { cors } from '@elysiajs/cors' | ||
|
||
import { req, responseShort, jsonResponse } from './setup' | ||
import { req, responseShort, imageResponse, jsonResponse } from './setup' | ||
import compression from '../src' | ||
|
||
describe(`elysia-compress`, () => { | ||
|
@@ -97,15 +98,40 @@ describe(`elysia-compress`, () => { | |
expect(res.headers.get('vary')).toBe('accept-encoding') | ||
}) | ||
|
||
it('return correct image type', async () => { | ||
it('return correct image', async () => { | ||
const app = new Elysia() | ||
.use(compression({ encodings: ['gzip'], threshold: 1 })) | ||
.get('/', () => Bun.file('tests/waifu.png')) | ||
.get('/', () => imageResponse) | ||
|
||
const res = await app.handle(req()) | ||
|
||
expect(res.headers.get('Content-Type')).toBe('image/png') | ||
expect(res.headers.get('vary')).toBeNull() | ||
|
||
const actualBody = await res.arrayBuffer() | ||
const expectedBody = await imageResponse.arrayBuffer() | ||
expect(actualBody).toEqual(expectedBody) | ||
}) | ||
|
||
it('return correct image from static plugin', async () => { | ||
const app = new Elysia() | ||
.use(staticPlugin({ assets: 'tests/images', prefix: '' })) | ||
.use(compression()) | ||
|
||
await app.modules | ||
|
||
const res = await app.handle( | ||
new Request('http://localhost/waifu.png', { | ||
headers: { 'accept-encoding': 'br, deflate, gzip, zstd' }, | ||
}), | ||
) | ||
|
||
expect(res.headers.get('Content-Type')).toBe('image/png') | ||
expect(res.headers.get('vary')).toBeNull() | ||
|
||
const actualBody = await res.arrayBuffer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the fix, the error here is:
|
||
const expectedBody = await imageResponse.arrayBuffer() | ||
expect(actualBody).toEqual(expectedBody) | ||
}) | ||
|
||
it('must be redirected to /not-found', async () => { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix. The other changes are tests and minor cleanup of issues found by my IDE.