Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,10 +1,11 @@
'use strict'
const t = require('tap')
const test = t.test
const sget = require('simple-get').concat
const { test } = require('node:test')
const assert = require('node:assert')
const fastify = require('..')()
test.after(() => fastify.close())
const opts = {
schema: {
response: {
@@ -60,81 +61,65 @@ fastify.get('/return-reply', opts, function (req, reply) {
return reply.send({ hello: 'world' })
})
fastify.listen({ port: 0 }, err => {
t.error(err)
t.teardown(() => { fastify.close() })
fastify.listen({ port: 0 }, (err, fastifyServer) => {
assert.ifError(err)
test('shorthand - sget return promise es6 get', t => {
test('shorthand - fetch return promise es6 get', async t => {
t.plan(4)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/return'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.equal(response.headers['content-length'], '' + body.length)
t.same(JSON.parse(body), { hello: 'world' })
})
const result = await fetch(`${fastifyServer}/return`)
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 200)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
})
test('shorthand - sget promise es6 get return error', t => {
test('shorthand - fetch promise es6 get return error', async t => {
t.plan(2)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/return-error'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 500)
})
const result = await fetch(`${fastifyServer}/return-error`)
t.assert.ok(!result.ok)
t.assert.strictEqual(result.status, 500)
})
test('sget promise double send', t => {
test('fetch promise double send', async t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/double'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(JSON.parse(body), { hello: '42' })
})
const result = await fetch(`${fastifyServer}/double`)
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 200)
const body = await result.text()
t.assert.deepStrictEqual(JSON.parse(body), { hello: '42' })
})
test('thenable', t => {
test('thenable', async t => {
t.plan(4)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/thenable'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.equal(response.headers['content-length'], '' + body.length)
t.same(JSON.parse(body), { hello: 'world' })
})
const result = await fetch(`${fastifyServer}/thenable`)
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 200)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
})
test('thenable (error)', t => {
test('thenable (error)', async t => {
t.plan(2)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/thenable-error'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 500)
})
const result = await fetch(`${fastifyServer}/thenable-error`)
t.assert.ok(!result.ok)
t.assert.strictEqual(result.status, 500)
})
test('return-reply', t => {
test('return-reply', async t => {
t.plan(4)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/return-reply'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.equal(response.headers['content-length'], '' + body.length)
t.same(JSON.parse(body), { hello: 'world' })
})
const result = await fetch(`${fastifyServer}/return-reply`)
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 200)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
})
})