fatsify核心功能示例测试!!!
This commit is contained in:
32
node_modules/fastify/test/bundler/esbuild/bundler-test.js
generated
vendored
Normal file
32
node_modules/fastify/test/bundler/esbuild/bundler-test.js
generated
vendored
Normal 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
10
node_modules/fastify/test/bundler/esbuild/package.json
generated
vendored
Normal 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"
|
||||
}
|
||||
}
|
||||
14
node_modules/fastify/test/bundler/esbuild/src/fail-plugin-version.js
generated
vendored
Normal file
14
node_modules/fastify/test/bundler/esbuild/src/fail-plugin-version.js
generated
vendored
Normal 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
|
||||
9
node_modules/fastify/test/bundler/esbuild/src/index.js
generated
vendored
Normal file
9
node_modules/fastify/test/bundler/esbuild/src/index.js
generated
vendored
Normal 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
|
||||
Reference in New Issue
Block a user