Skip to main content
Glama
async-await.test.js1.47 kB
'use strict' const { test } = require('node:test') 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.assert.strictEqual(res.payload, 'hello') } catch (err) { t.assert.fail(err) } }) test('basic async await (errored)', async t => { const dispatch = function (_req, res) { res.connection.destroy(new Error('kaboom')) } 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) { 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.assert.strictEqual(res.payload, 'hello') } catch (err) { t.assert.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.assert.strictEqual(res.payload, 'hello') } catch (err) { t.assert.fail(err) } })

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/krtw00/search-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server