Projektstart
This commit is contained in:
55
backend/node_modules/light-my-request/test/async-await.test.js
generated
vendored
Normal file
55
backend/node_modules/light-my-request/test/async-await.test.js
generated
vendored
Normal 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)
|
||||
}
|
||||
})
|
||||
2110
backend/node_modules/light-my-request/test/index.test.js
generated
vendored
Normal file
2110
backend/node_modules/light-my-request/test/index.test.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
16
backend/node_modules/light-my-request/test/request.test.js
generated
vendored
Normal file
16
backend/node_modules/light-my-request/test/request.test.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
|
||||
const Request = require('../lib/request')
|
||||
|
||||
test('aborted property should be false', async (t) => {
|
||||
const mockReq = {
|
||||
url: 'http://localhost',
|
||||
method: 'GET',
|
||||
headers: {}
|
||||
}
|
||||
const req = new Request(mockReq)
|
||||
|
||||
t.same(req.aborted, false)
|
||||
})
|
||||
17
backend/node_modules/light-my-request/test/response.test.js
generated
vendored
Normal file
17
backend/node_modules/light-my-request/test/response.test.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
|
||||
const Response = require('../lib/response')
|
||||
|
||||
test('multiple calls to res.destroy should not be called', (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const mockReq = {}
|
||||
const res = new Response(mockReq, (err, response) => {
|
||||
t.error(err)
|
||||
})
|
||||
|
||||
res.destroy()
|
||||
res.destroy()
|
||||
})
|
||||
Reference in New Issue
Block a user