node-clinic/test/cli-autocannon.test.js
Rafael Gonzaga 87e8a215dc
chore: add ci support node 16 (#292)
* chore: bump tap version

* chore: add v16 to test matrix

* chore: update coverage settings to latest tap version

* chore: use taprc

* chore: support v17

* chore: updade coverage settings
2021-10-28 09:41:21 -03:00

63 lines
1.8 KiB
JavaScript

'use strict'
const test = require('tap').test
const cli = require('./cli.js')
const raw = String.raw
test('clinic --autocannon with $PORT', function (t) {
cli({ relayStderr: false }, [
'clinic', 'doctor', '--no-open',
'--autocannon', '[', 'localhost:$PORT', '-d', '1', ']',
'--', 'node', '-e', `
const http = require('http')
http.createServer((req, res) => res.end('ok')).listen(0)
`
], function (err, stdout, stderr) {
t.error(err)
t.ok(stderr.indexOf('Running 1s test @ http://localhost:') > -1)
t.equal(stdout.split('\n')[0], 'Analysing data')
t.end()
})
})
test('clinic --autocannon with escaped $', function (t) {
cli({ relayStderr: false }, [
'clinic', 'doctor', '--no-open',
'--autocannon', '[', raw`localhost:$PORT/\$PORT?\$page=10`, '-d', '1', ']',
'--', 'node', '-e', `
const http = require('http')
let first = true
http.createServer((req, res) => {
if (first) console.log(req.url)
first = false
res.end('ok')
}).listen(0)
`
], function (err, stdout, stderr) {
t.error(err)
t.ok(stderr.indexOf('Running 1s test @ http://localhost:') > -1)
t.equal(stdout.split('\n')[0], '/$PORT?$page=10')
t.equal(stdout.split('\n')[1], 'Analysing data')
t.end()
})
})
test('clinic --autocannon with /path', function (t) {
cli({ relayStderr: false }, [
'clinic', 'doctor', '--no-open',
'--autocannon', '[', '/path', '-d', '1', ']',
'--', 'node', '-e', `
const http = require('http')
http.createServer((req, res) => res.end(req.url)).listen(0)
`
], function (err, stdout, stderr) {
t.error(err)
t.ok(stderr.indexOf('Running 1s test @ http://localhost:') > -1)
t.equal(stdout.split('\n')[0], 'Analysing data')
t.end()
})
})