Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions test/examples.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict'

const { tspl } = require('@matteo.collina/tspl')
const { createServer } = require('node:http')
const { test, after } = require('node:test')
const { once } = require('node:events')
const examples = require('../docs/examples/request.js')

test('request examples', async (t) => {
t = tspl(t, { plan: 7 })
t.plan(7)

let lastReq
const exampleServer = createServer({ joinDuplicateHeaders: true }, (req, res) => {
Expand Down Expand Up @@ -48,21 +47,19 @@ test('request examples', async (t) => {
])

await examples.getRequest(exampleServer.address().port)
t.strictEqual(lastReq.method, 'GET')
t.assert.strictEqual(lastReq.method, 'GET')

await examples.postJSONRequest(exampleServer.address().port)
t.strictEqual(lastReq.method, 'POST')
t.strictEqual(lastReq.headers['content-type'], 'application/json')
t.assert.strictEqual(lastReq.method, 'POST')
t.assert.strictEqual(lastReq.headers['content-type'], 'application/json')

await examples.postFormRequest(exampleServer.address().port)
t.strictEqual(lastReq.method, 'POST')
t.strictEqual(lastReq.headers['content-type'], 'application/x-www-form-urlencoded')
t.assert.strictEqual(lastReq.method, 'POST')
t.assert.strictEqual(lastReq.headers['content-type'], 'application/x-www-form-urlencoded')

await examples.deleteRequest(exampleServer.address().port)
t.strictEqual(lastReq.method, 'DELETE')
t.assert.strictEqual(lastReq.method, 'DELETE')

await examples.deleteRequest(errorServer.address().port)
t.strictEqual(lastReq.method, 'DELETE')

await t.completed
t.assert.strictEqual(lastReq.method, 'DELETE')
})
2 changes: 1 addition & 1 deletion test/parser-issues.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { tspl } = require('@matteo.collina/tspl')
const { test } = require('node:test')
const { test, after } = require('node:test')
const net = require('node:net')
const { Client, errors, fetch } = require('..')

Expand Down
Loading