Split out of actions/toolkit (packages/http-client, history kept by filter-repo). Brings the 2024 [LevK] packaging edits forward onto current upstream: - tsconfig.json: the monorepo root's compiler options inlined, no extends - jest.config.cjs: the root's ts-jest transform, rooted at tests/ (isolatedModules: ESM lib/ and sources run through CommonJS) - __tests__/ -> tests/ - package.json: test = jest, build = tsc; jest/ts-jest/typescript as devDependencies; repository, homepage, bugs on git.levk.dev - .gitignore: node_modules/, lib/, audit.json - HttpCodes.PayloadTooLarge = 413 (the 2024 edit; still missing upstream) Not carried over from 2024: the _getExistingOrDefaultHeader type narrowing (upstream has since fixed it properly), version reset to 1.0.0 (dependents' ranges need upstream's numbering) and the Unlicense field (the code is MIT). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UHXzGrsxfkGk8LmwrBbHNZ
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import * as httpm from '../lib'
|
|
|
|
describe('basics', () => {
|
|
let _http: httpm.HttpClient
|
|
|
|
beforeEach(() => {
|
|
_http = new httpm.HttpClient('http-client-tests', [], {keepAlive: true})
|
|
})
|
|
|
|
afterEach(() => {
|
|
_http.dispose()
|
|
})
|
|
|
|
it.each([true, false])('creates Agent with keepAlive %s', keepAlive => {
|
|
const http = new httpm.HttpClient('http-client-tests', [], {keepAlive})
|
|
const agent = http.getAgent('https://postman-echo.com')
|
|
expect(agent).toHaveProperty('keepAlive', keepAlive)
|
|
})
|
|
|
|
it('does basic http get request with keepAlive true', async () => {
|
|
const res: httpm.HttpClientResponse = await _http.get(
|
|
'https://postman-echo.com/get'
|
|
)
|
|
expect(res.message.statusCode).toBe(200)
|
|
const body: string = await res.readBody()
|
|
const obj = JSON.parse(body)
|
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
|
})
|
|
|
|
it('does basic head request with keepAlive true', async () => {
|
|
const res: httpm.HttpClientResponse = await _http.head(
|
|
'https://postman-echo.com/get'
|
|
)
|
|
expect(res.message.statusCode).toBe(200)
|
|
})
|
|
|
|
it('does basic http delete request with keepAlive true', async () => {
|
|
const res: httpm.HttpClientResponse = await _http.del(
|
|
'https://postman-echo.com/delete'
|
|
)
|
|
expect(res.message.statusCode).toBe(200)
|
|
const body: string = await res.readBody()
|
|
JSON.parse(body)
|
|
})
|
|
|
|
it('does basic http post request with keepAlive true', async () => {
|
|
const b = 'Hello World!'
|
|
const res: httpm.HttpClientResponse = await _http.post(
|
|
'https://postman-echo.com/post',
|
|
b
|
|
)
|
|
expect(res.message.statusCode).toBe(200)
|
|
const body: string = await res.readBody()
|
|
const obj = JSON.parse(body)
|
|
expect(obj.data).toBe(b)
|
|
expect(obj.url).toBe('https://postman-echo.com/post')
|
|
})
|
|
|
|
it('does basic http patch request with keepAlive true', async () => {
|
|
const b = 'Hello World!'
|
|
const res: httpm.HttpClientResponse = await _http.patch(
|
|
'https://postman-echo.com/patch',
|
|
b
|
|
)
|
|
expect(res.message.statusCode).toBe(200)
|
|
const body: string = await res.readBody()
|
|
const obj = JSON.parse(body)
|
|
expect(obj.data).toBe(b)
|
|
expect(obj.url).toBe('https://postman-echo.com/patch')
|
|
})
|
|
|
|
it('does basic http options request with keepAlive true', async () => {
|
|
const res: httpm.HttpClientResponse = await _http.options(
|
|
'https://postman-echo.com'
|
|
)
|
|
expect(res.message.statusCode).toBe(200)
|
|
await res.readBody()
|
|
})
|
|
})
|