Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
a5a9a0f
chore: remove tap
ilteoood Jan 1, 2025
2e52f58
chore: content type promises
ilteoood Jan 1, 2025
b8578c3
chore: removed simple get
ilteoood Jan 1, 2025
b76489c
chore: listen as promise
ilteoood Jan 1, 2025
04b4905
chore: prefixAvoidTrailingSlash
ilteoood Jan 2, 2025
d5f8d38
fix: register /static
ilteoood Jan 2, 2025
72468c1
feat: static
ilteoood Jan 3, 2025
edeece6
feat: static static2
ilteoood Jan 3, 2025
b4e1ca1
chore: constraints
ilteoood Jan 3, 2025
80f65fb
chore: payload path
ilteoood Jan 3, 2025
d34908c
chore: error handler
ilteoood Jan 3, 2025
27fa33d
fix: not found
ilteoood Jan 3, 2025
af454c2
chore: not foundhandler
ilteoood Jan 3, 2025
073effc
chore: serving disabled
ilteoood Jan 3, 2025
be4b33b
chore: sendFile
ilteoood Jan 3, 2025
1224311
chore: sendFile disabled
ilteoood Jan 3, 2025
dd9751f
chore: allowedPath
ilteoood Jan 3, 2025
30cff99
chore: allowed path request
ilteoood Jan 3, 2025
d66ff12
chore: download
ilteoood Jan 3, 2025
a50045f
chore: sendFile
ilteoood Jan 3, 2025
c7cd358
chore: removed duplicated test
ilteoood Jan 3, 2025
2dccee5
chore: download disabled
ilteoood Jan 3, 2025
4544b3b
chore: tests
ilteoood Jan 3, 2025
11eee29
chore: send options
ilteoood Jan 3, 2025
e8e5dc8
chore: setHeaders option
ilteoood Jan 3, 2025
41a153a
chore: maxAge
ilteoood Jan 3, 2025
ae8c5fc
chore: errors
ilteoood Jan 3, 2025
0059a7c
chore: register no prefix
ilteoood Jan 3, 2025
e8e0ff7
chore: compress
ilteoood Jan 3, 2025
c6660e9
chore: register static schema hide
ilteoood Jan 3, 2025
98bc636
chore: register static schema hide
ilteoood Jan 3, 2025
9a782e3
chore: register static without schema hide
ilteoood Jan 3, 2025
8045459
chore: exposeHeadRoutes
ilteoood Jan 3, 2025
e195a5b
chore: wildcard false
ilteoood Jan 3, 2025
fc2cb36
chore: wildcard + trailing slash
ilteoood Jan 3, 2025
a03f0ea
chore: deps
ilteoood Jan 3, 2025
35072dd
chore: register with wildcard
ilteoood Jan 3, 2025
8e053f1
chore: static with wildcard alternative index
ilteoood Jan 4, 2025
c1f0ae7
chore: static with redirect
ilteoood Jan 4, 2025
3b82e1e
feat: static with redirect and not wildcard
ilteoood Jan 4, 2025
fb3f99c
chore: trailing slash behaviour
ilteoood Jan 4, 2025
340893c
chore: dotfiles
ilteoood Jan 4, 2025
4fdce1d
chore: fail glob
ilteoood Jan 4, 2025
d25a37a
chore: enoent
ilteoood Jan 4, 2025
c47b184
chore: premature stream close
ilteoood Jan 4, 2025
0df6a0d
chore: .br
ilteoood Jan 4, 2025
d0bd348
chore: percent encoded
ilteoood Jan 4, 2025
df4dc12
chore: static and static2 wildcard
ilteoood Jan 4, 2025
8b233af
chore: headers get
ilteoood Jan 4, 2025
31709ca
chore: erorr headers get
ilteoood Jan 4, 2025
08a7d7a
chore: redirect
ilteoood Jan 4, 2025
8ec06f5
chore: serve index false
ilteoood Jan 4, 2025
7d1a483
chore: symbolik link
ilteoood Jan 4, 2025
7363f6f
chore: serve hidden dir with false wildcard
ilteoood Jan 4, 2025
fb00a02
chore: not found hidden
ilteoood Jan 4, 2025
0c06baf
chore: wildcard
ilteoood Jan 4, 2025
1ee373c
chore: content length
ilteoood Jan 4, 2025
81fb6d7
chore: respect .code
ilteoood Jan 4, 2025
bc3b49b
chore: respect .type
ilteoood Jan 4, 2025
4903e02
chore: removed simple
ilteoood Jan 4, 2025
a74add6
chore: dir list wrong
ilteoood Jan 4, 2025
f39769b
fix: dir list
ilteoood Jan 4, 2025
d444970
fix: dir list custom options
ilteoood Jan 4, 2025
aaa8917
chore: html format
ilteoood Jan 4, 2025
3621d24
chore: dir list
ilteoood Jan 4, 2025
8f7256a
dir list html format
ilteoood Jan 4, 2025
fcf52fb
chore: dir list
ilteoood Jan 4, 2025
b8ef3c7
chore: dir list json
ilteoood Jan 4, 2025
f1020a7
chore: json format
ilteoood Jan 4, 2025
264bc94
chore: json format
ilteoood Jan 4, 2025
03b3d8c
chore: html format
ilteoood Jan 4, 2025
c02e5f2
chore: list html
ilteoood Jan 4, 2025
b379ab9
chore: not existing dirs
ilteoood Jan 4, 2025
e3aff0a
chore: dir with dotfiles
ilteoood Jan 4, 2025
b8f1115
chore: dir with dotfiles
ilteoood Jan 4, 2025
7fb1789
chore: arrange
ilteoood Jan 4, 2025
b92c445
chore: static
ilteoood Jan 4, 2025
3aff483
chore: close
ilteoood Jan 4, 2025
ca53b1d
chore: rejects
ilteoood Jan 4, 2025
b5ed7f9
chore: removed simple-get
ilteoood Jan 4, 2025
edef0cf
chore: deepStrictEqual
ilteoood Jan 5, 2025
b1f2b75
chore: use c8
ilteoood Jan 5, 2025
cea275c
chore: withResolvers polyfill
ilteoood Jan 5, 2025
28ad95d
fix: pattern
ilteoood Jan 5, 2025
8ba0eb1
Update test/static.test.js
ilteoood Jan 5, 2025
bbb1b10
chore: equal
ilteoood Jan 5, 2025
c751ab6
fix: pattern test folder
ilteoood Jan 5, 2025
099110c
chore: removed additional --test
ilteoood Jan 6, 2025
03ad7c5
fix: pattern
ilteoood Jan 6, 2025
5950937
chore: switch to borp
ilteoood Jan 9, 2025
d1ec8d7
Update package.json
ilteoood Jan 9, 2025
872c7f9
Update package.json
ilteoood Jan 9, 2025
0778ae2
chore: c8
ilteoood Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .taprc

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"coverage": "npm run test:unit -- --coverage-report=html",
"coverage": "c8 --reporter html borp --coverage --check-coverage --lines 100",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap",
"test:unit": "borp -C --check-coverage --lines 100",
"example": "node example/server.js"
},
"repository": {
Expand Down Expand Up @@ -69,14 +69,14 @@
"@fastify/compress": "^8.0.0",
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"borp": "^0.19.0",
"c8": "^10.1.3",
"concat-stream": "^2.0.0",
"eslint": "^9.17.0",
"fastify": "^5.1.0",
"neostandard": "^0.12.0",
"pino": "^9.1.0",
"proxyquire": "^2.1.3",
"simple-get": "^4.0.1",
"tap": "^18.7.1",
"tsd": "^0.31.0"
},
"tsd": {
Expand Down
224 changes: 97 additions & 127 deletions test/content-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
/* eslint n/no-deprecated-api: "off" */

const path = require('node:path')
const { test } = require('tap')
const simple = require('simple-get')
const { test } = require('node:test')
const Fastify = require('fastify')

const fastifyStatic = require('../')

test('register /content-type', t => {
t.plan(6)
test('register /content-type', async t => {
t.plan(5)

const pluginOptions = {
root: path.join(__dirname, '/content-type'),
Expand All @@ -19,72 +18,55 @@ test('register /content-type', t => {
const fastify = Fastify()
fastify.register(fastifyStatic, pluginOptions)

t.teardown(fastify.close.bind(fastify))
t.after(() => fastify.close())

fastify.listen({ port: 0 }, (err) => {
t.error(err)
await fastify.listen({ port: 0 })

fastify.server.unref()
fastify.server.unref()

t.test('/content-type/index.html', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.html'
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
})
})
await t.test('/content-type/index.html', async (t) => {
t.plan(2)

t.test('/content-type/index.css', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.css'
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'text/css; charset=utf-8')
})
})
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.html')
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8')
})

t.test('/content-type/sample.jpg', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg'
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'image/jpeg')
})
})
await t.test('/content-type/index.css', async (t) => {
t.plan(2)

t.test('/content-type/test.txt', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/test.txt'
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'text/plain; charset=utf-8')
})
})
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.css')
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/css; charset=utf-8')
})

t.test('/content-type/binary', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/binary'
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'application/octet-stream')
})
})
await t.test('/content-type/sample.jpg', async (t) => {
t.plan(2)

const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg')
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'image/jpeg')
})

await t.test('/content-type/test.txt', async (t) => {
t.plan(2)

const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/test.txt')
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/plain; charset=utf-8')
})

await t.test('/content-type/binary', async (t) => {
t.plan(2)

const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/binary')
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'application/octet-stream')
})
})

test('register /content-type preCompressed', t => {
t.plan(6)
test('register /content-type preCompressed', async t => {
t.plan(5)

const pluginOptions = {
root: path.join(__dirname, '/content-type'),
Expand All @@ -94,81 +76,69 @@ test('register /content-type preCompressed', t => {
const fastify = Fastify()
fastify.register(fastifyStatic, pluginOptions)

t.teardown(fastify.close.bind(fastify))

fastify.listen({ port: 0 }, (err) => {
t.error(err)

fastify.server.unref()

t.test('/content-type/index.html', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.html',
headers: {
'accept-encoding': 'gzip, deflate, br'
}
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
})
t.after(() => fastify.close())

await fastify.listen({ port: 0 })

fastify.server.unref()

await t.test('/content-type/index.html', async (t) => {
t.plan(2)

const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.html', {
headers: {
'accept-encoding': 'gzip, deflate, br'
}
})
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8')
})

await t.test('/content-type/index.css', async (t) => {
t.plan(2)

t.test('/content-type/index.css', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.css',
headers: {
'accept-encoding': 'gzip, deflate, br'
}
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'text/css; charset=utf-8')
})
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.css', {
headers: {
'accept-encoding': 'gzip, deflate, br'
}
})
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/css; charset=utf-8')
})

await t.test('/content-type/sample.jpg', async (t) => {
t.plan(2)

t.test('/content-type/sample.jpg', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg',
headers: {
'accept-encoding': 'gzip, deflate, br'
}
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'image/jpeg')
})
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg', {
headers: {
'accept-encoding': 'gzip, deflate, br'
}
})
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'image/jpeg')
})

t.test('/content-type/test.txt', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/test.txt',
headers: {
'accept-encoding': 'gzip, deflate, br'
}
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'text/plain; charset=utf-8')
})
await t.test('/content-type/test.txt', async (t) => {
t.plan(2)

const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/test.txt', {
headers: {
'accept-encoding': 'gzip, deflate, br'
}
})
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/plain; charset=utf-8')
})

await t.test('/content-type/binary', async (t) => {
t.plan(2)

t.test('/content-type/binary', (t) => {
t.plan(2)
simple.concat({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/content-type/binary',
headers: {
'accept-encoding': 'gzip, deflate, br'
}
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'application/octet-stream')
})
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/binary', {
headers: {
'accept-encoding': 'gzip, deflate, br'
}
})
t.assert.ok(response.ok)
t.assert.deepStrictEqual(response.headers.get('content-type'), 'application/octet-stream')
})
})
Loading
Loading