Skip to content

Commit

Permalink
Tests. Default opts
Browse files Browse the repository at this point in the history
  • Loading branch information
milesnash committed Apr 25, 2023
1 parent 0282b40 commit 591c5ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autocannon.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports.track = track
module.exports.start = start
module.exports.printResult = printResult
module.exports.parseArguments = parseArguments
module.exports.aggregateResult = function aggregateResult (results, opts) {
module.exports.aggregateResult = function aggregateResult (results, opts = {}) {
if (!Array.isArray(results)) {
throw new Error('"results" must be an array of results')
}
Expand Down
33 changes: 33 additions & 0 deletions test/aggregateResult.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { test } = require('tap')
const { startServer } = require('./helper')
const autocannon = require('../autocannon')
const aggregateResult = autocannon.aggregateResult
const server = startServer()
const url = 'http://localhost:' + server.address().port

test('exec separate autocannon instances with skipAggregateResult, then aggregateResult afterwards', async (t) => {
t.plan(2)

const opts = {
url,
connections: 1,
maxOverallRequests: 10,
skipAggregateResult: true
}

const results = await Promise.all([
autocannon(opts),
autocannon(opts)
])

const aggregateResults = aggregateResult(results, opts)

t.equal(aggregateResults['2xx'], 20)
t.equal(aggregateResults.requests.total, 20)
})

test('aggregateResult must be passed opts with at least a URL or socketPath property', async (t) => {
t.plan(2)
t.throws(() => aggregateResult([]), 'url or socketPath option required')
t.throws(() => aggregateResult([], {}), 'url or socketPath option required')
})

0 comments on commit 591c5ef

Please sign in to comment.