Skip to content

Commit 463979b

Browse files
committed
Added a test that ensures hono issue 4563 stays fixed
1 parent fe293ac commit 463979b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

test/serve-static.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Hono } from 'hono'
22
import request from 'supertest'
3-
import { chmodSync, statSync } from 'node:fs'
3+
import { chmodSync, rmSync, statSync, symlinkSync } from 'node:fs'
44
import path from 'node:path'
55
import { serveStatic } from './../src/serve-static'
66
import { createAdaptorServer } from './../src/server'
@@ -198,6 +198,22 @@ describe('Serve Static Middleware', () => {
198198
expect(res.status).toBe(404)
199199
})
200200

201+
it('Should follow symlinks', async () => {
202+
const symlinkPath = path.join(__dirname, 'assets', 'static', 'symlink.html')
203+
const symlinkTarget = path.join(__dirname, 'assets', 'static', 'index.html')
204+
try {
205+
// force: true so it doesn't throw if the symlink doesn't exist
206+
rmSync(symlinkPath, { force: true })
207+
symlinkSync(symlinkTarget, symlinkPath)
208+
209+
const res = await request(server).get('/static/symlink.html')
210+
expect(res.status).toBe(200)
211+
expect(res.text).toBe('<h1>Hello Hono</h1>')
212+
} finally {
213+
rmSync(symlinkPath, { force: true })
214+
}
215+
})
216+
201217
it('Should handle URIError thrown while decoding URI component', async () => {
202218
const res = await request(server).get('/static/%c0%afsecret.txt')
203219
expect(res.status).toBe(404)

0 commit comments

Comments
 (0)