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,32 +1,32 @@
'use strict'
const { test } = require('tap')
const { test } = require('node:test')
const inject = require('../index')
test('basic async await', async t => {
const dispatch = function (req, res) {
const dispatch = function (_req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('hello')
}
try {
const res = await inject(dispatch, { method: 'GET', url: 'http://example.com:8080/hello' })
t.equal(res.payload, 'hello')
t.assert.strictEqual(res.payload, 'hello')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
})
test('basic async await (errored)', async t => {
const dispatch = function (req, res) {
const dispatch = function (_req, res) {
res.connection.destroy(new Error('kaboom'))
}
await t.rejects(inject(dispatch, { method: 'GET', url: 'http://example.com:8080/hello' }))
await t.assert.rejects(() => inject(dispatch, { method: 'GET', url: 'http://example.com:8080/hello' }), Error)
})
test('chainable api with async await', async t => {
const dispatch = function (req, res) {
const dispatch = function (_req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('hello')
}
@@ -34,22 +34,22 @@ test('chainable api with async await', async t => {
try {
const chain = inject(dispatch).get('http://example.com:8080/hello')
const res = await chain.end()
t.equal(res.payload, 'hello')
t.assert.strictEqual(res.payload, 'hello')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
})
test('chainable api with async await without end()', async t => {
const dispatch = function (req, res) {
const dispatch = function (_req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('hello')
}
try {
const res = await inject(dispatch).get('http://example.com:8080/hello')
t.equal(res.payload, 'hello')
t.assert.strictEqual(res.payload, 'hello')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
})