fatsify核心功能示例测试!!!

This commit is contained in:
2025-09-21 14:50:41 +08:00
commit 9145aea047
1958 changed files with 230098 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
'use strict'
const { test } = require('node:test')
const fastifySuccess = require('./dist/success')
const fastifyFailPlugin = require('./dist/failPlugin')
test('Bundled package should work', (t, done) => {
t.plan(4)
fastifySuccess.ready((err) => {
t.assert.ifError(err)
fastifySuccess.inject(
{
method: 'GET',
url: '/'
},
(error, res) => {
t.assert.ifError(error)
t.assert.strictEqual(res.statusCode, 200)
t.assert.deepStrictEqual(res.json(), { hello: 'world' })
done()
}
)
})
})
test('Bundled package should not work with bad plugin version', (t, done) => {
t.plan(1)
fastifyFailPlugin.ready((err) => {
t.assert.match(err.message, /expected '9.x' fastify version/i)
done()
})
})

10
node_modules/fastify/test/bundler/esbuild/package.json generated vendored Normal file
View File

@@ -0,0 +1,10 @@
{
"version": "0.0.1",
"scripts": {
"bundle": "esbuild success=src/index.js failPlugin=src/fail-plugin-version.js --bundle --outdir=dist --platform=node",
"test": "npm run bundle && node bundler-test.js"
},
"devDependencies": {
"esbuild": "^0.25.0"
}
}

View File

@@ -0,0 +1,14 @@
'use strict'
const fp = require('fastify-plugin')
const fastify = require('../../../../')()
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})
fastify.register(fp((instance, opts, done) => {
done()
}, { fastify: '9.x' }))
module.exports = fastify

View File

@@ -0,0 +1,9 @@
'use strict'
const fastify = require('../../../../')()
// Declare a route
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})
module.exports = fastify