Skip to content

Commit

Permalink
add tests for #234 (#391)
Browse files Browse the repository at this point in the history
* add tests for #234

* change description

* use variable to store file contents
  • Loading branch information
gurgunday authored Jul 17, 2023
1 parent eb133ce commit e505f56
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/static-encode/[...]/a .md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example
37 changes: 37 additions & 0 deletions test/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3756,6 +3756,7 @@ t.test(
t.end()
}
)

t.test(
'converts URL to path',
async (t) => {
Expand Down Expand Up @@ -3803,3 +3804,39 @@ t.test(
t.same(response.body, foobarContent)
}
)

t.test(
'serves files with paths that have characters modified by encodeUri when wildcard is false',
async (t) => {
const aContent = fs.readFileSync(path.join(__dirname, 'static-encode/[...]', 'a .md'), 'utf-8')

t.plan(4)
const pluginOptions = {
root: url.pathToFileURL(path.join(__dirname, '/static-encode')),
wildcard: false
}

const fastify = Fastify()

fastify.register(fastifyStatic, pluginOptions)
const response = await fastify.inject({
method: 'GET',
url: '[...]/a .md',
headers: {
'accept-encoding': '*, *'
}
})
t.equal(response.statusCode, 200)
t.same(response.body, aContent)

const response2 = await fastify.inject({
method: 'GET',
url: '%5B...%5D/a%20.md',
headers: {
'accept-encoding': '*, *'
}
})
t.equal(response2.statusCode, 200)
t.same(response2.body, aContent)
}
)

0 comments on commit e505f56

Please sign in to comment.