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

fix: correct fastify version on plugin genration #804

Merged
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 templates/plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ module.exports = fp(async function (fastify, opts) {
fastify.decorate('exampleDecorator', () => {
return 'decorated'
})
}, { fastify: '^4.x' })
}, { fastify: '^5.x' })
20 changes: 19 additions & 1 deletion test/generate-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const templateDir = path.join(__dirname, '..', 'templates', 'plugin')
const cliPkg = require('../package')
const { exec, execSync } = require('node:child_process')
const strip = require('strip-ansi')
const semver = require('semver')

const expected = {}
const initVersion = execSync('npm get init-version').toString().trim()

Expand Down Expand Up @@ -100,16 +102,32 @@ function define (t) {
})

test('should finish succesfully', async (t) => {
t.plan(17 + Object.keys(expected).length)
t.plan(18 + Object.keys(expected).length)
try {
await generate(workdir, pluginTemplate)
await verifyPkg(t)
await verifyCopy(t, expected)
await verifyFastifyPluginVersion(t)
} catch (err) {
t.error(err)
}
})

function verifyFastifyPluginVersion (t) {
return new Promise((resolve, reject) => {
const pluginPath = path.join(workdir, 'index.js')
const plugin = require(pluginPath)
const pkgPath = path.join(__dirname, '../', 'package.json')
const pkg = require(pkgPath)
const pluginMeta = plugin[Symbol.for('plugin-meta')]
const pluginVersion = pluginMeta.fastify
const pkgVersion = pkg.dependencies.fastify
const satified = semver.intersects(pluginVersion, pkgVersion)
t.ok(satified, 'meta should be the same')
resolve()
})
}

function verifyPkg (t) {
return new Promise((resolve, reject) => {
const pkgFile = path.join(workdir, 'package.json')
Expand Down