Skip to content
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

Merge next into master #241

Merged
merged 6 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.1.0
with:
lint: true
license-check: true
7 changes: 2 additions & 5 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
ts: false
jsx: false
flow: false
coverage: true

files:
- test/**/*.js
plugin:
- "!@tapjs/typescript"
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
},
"homepage": "https://github.com/fastify/fastify-plugin#readme",
"devDependencies": {
"@fastify/type-provider-typebox": "^4.0.0",
"@types/node": "^20.1.0",
"fastify": "^4.0.1",
"@fastify/pre-commit": "^2.1.0",
"@fastify/type-provider-typebox": "^5.0.0-pre.fv5.1",
"@types/node": "^20.11.20",
"fastify": "^5.0.0-alpha.2",
"proxyquire": "^2.1.3",
"standard": "^17.0.0",
"tap": "^16.0.1",
"standard": "^17.1.0",
"tap": "^18.7.0",
"tsd": "^0.31.0"
}
}
56 changes: 31 additions & 25 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const test = t.test
const fp = require('../plugin')
const Fastify = require('fastify')

const pkg = require('../package.json')

test('fastify-plugin is a function', t => {
t.plan(1)
t.type(fp, 'function')
Expand Down Expand Up @@ -206,12 +208,12 @@ test('should check fastify dependency graph - plugin', t => {
const fastify = Fastify()

fastify.register(fp((fastify, opts, next) => next(), {
fastify: '4.x',
fastify: '5.x',
name: 'plugin1-name'
}))

fastify.register(fp((fastify, opts, next) => next(), {
fastify: '4.x',
fastify: '5.x',
name: 'test',
dependencies: ['plugin1-name', 'plugin2-name']
}))
Expand All @@ -226,12 +228,12 @@ test('should check fastify dependency graph - decorate', t => {
const fastify = Fastify()

fastify.decorate('plugin1', fp((fastify, opts, next) => next(), {
fastify: '4.x',
fastify: '5.x',
name: 'plugin1-name'
}))

fastify.register(fp((fastify, opts, next) => next(), {
fastify: '4.x',
fastify: '5.x',
name: 'test',
decorators: { fastify: ['plugin1', 'plugin2'] }
}))
Expand All @@ -246,12 +248,12 @@ test('should check fastify dependency graph - decorateReply', t => {
const fastify = Fastify()

fastify.decorateReply('plugin1', fp((fastify, opts, next) => next(), {
fastify: '4.x',
fastify: '5.x',
name: 'plugin1-name'
}))

fastify.register(fp((fastify, opts, next) => next(), {
fastify: '4.x',
fastify: '5.x',
name: 'test',
decorators: { reply: ['plugin1', 'plugin2'] }
}))
Expand Down Expand Up @@ -311,20 +313,24 @@ test('should check dependencies when encapsulated', t => {
})
})

test('should check version when encapsulated', t => {
t.plan(1)
const fastify = Fastify()
test(
'should check version when encapsulated',
{ skip: /\d-.+/.test(pkg.devDependencies.fastify) },
t => {
t.plan(1)
const fastify = Fastify()

fastify.register(fp((fastify, opts, next) => next(), {
name: 'test',
fastify: '<=2.10.0',
encapsulate: true
}))
fastify.register(fp((fastify, opts, next) => next(), {
name: 'test',
fastify: '<=2.10.0',
encapsulate: true
}))

fastify.ready(err => {
t.match(err.message, /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d+.\d+' is installed/)
})
})
fastify.ready(err => {
t.match(err.message, /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d+.\d+' is installed/)
})
}
)

test('should check decorators when encapsulated', t => {
t.plan(1)
Expand All @@ -333,7 +339,7 @@ test('should check decorators when encapsulated', t => {
fastify.decorate('plugin1', 'foo')

fastify.register(fp((fastify, opts, next) => next(), {
fastify: '4.x',
fastify: '5.x',
name: 'test',
encapsulate: true,
decorators: { fastify: ['plugin1', 'plugin2'] }
Expand All @@ -352,14 +358,14 @@ test('plugin name when encapsulated', async t => {
})

fastify.register(fp(getFn('hello'), {
fastify: '4.x',
fastify: '5.x',
name: 'hello',
encapsulate: true
}))

fastify.register(function plugin (fastify, opts, next) {
fastify.register(fp(getFn('deep'), {
fastify: '4.x',
fastify: '5.x',
name: 'deep',
encapsulate: true
}))
Expand All @@ -368,25 +374,25 @@ test('plugin name when encapsulated', async t => {
t.equal(fastify.pluginName, 'deep-deep', 'should be deep-deep')

fastify.register(fp(getFn('deep-deep-deep'), {
fastify: '4.x',
fastify: '5.x',
name: 'deep-deep-deep',
encapsulate: true
}))

fastify.register(fp(getFn('deep-deep -> not-encapsulated-2'), {
fastify: '4.x',
fastify: '5.x',
name: 'not-encapsulated-2'
}))

next()
}, {
fastify: '4.x',
fastify: '5.x',
name: 'deep-deep',
encapsulate: true
}))

fastify.register(fp(getFn('plugin -> not-encapsulated'), {
fastify: '4.x',
fastify: '5.x',
name: 'not-encapsulated'
}))

Expand Down
Loading