Projektstart

This commit is contained in:
2026-01-22 15:49:12 +01:00
parent 7212eb6f7a
commit 57e5f652f8
10637 changed files with 2598792 additions and 64 deletions

View File

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