Skip to content

Commit 100185d

Browse files
committed
test: make tests run sequentially, exit
1 parent 91ea8dc commit 100185d

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

tests/test.js

+28-15
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ w.add('JSON body content-type header', async (result) => {
452452
result(res.statusCode === 200, res.body.toString())
453453
})
454454

455-
w.add('Ensure that per-request options do not persist within defaults', async (result) => {
455+
w.add('Ensure that per-request options do not persist between defaults', async (result) => {
456456
const def = pp.defaults({
457457
'url': 'http://localhost:5136/testget',
458458
'timeout': 1000
@@ -467,23 +467,36 @@ w.add('Ensure that per-request options do not persist within defaults', async (r
467467
result(r1.body.toString() === 'hey' && r2.body.toString() === 'Hi.', r1.body.toString() + ' ' + r2.body.toString())
468468
})
469469

470-
const runTests = () => {
471-
w.forEach((entry) => {
472-
const result = (r, message) => {
473-
if (r) {
474-
console.log("OK", entry[0], message)
475-
} else {
476-
console.error("Fail", entry[0], message)
477-
}
470+
let fail = false
471+
472+
const runTest = (i) => {
473+
const entry = w[i]
474+
console.log(i, "running", entry[0])
475+
const result = (r, message) => {
476+
if (r) {
477+
console.log("> OK", entry[0], message)
478+
} else {
479+
fail = true
480+
console.error("> Fail", entry[0], message)
478481
}
479-
if (entry[1].hasOwnProperty('then')) {
480-
entry[1](result).catch((err) => {
481-
console.error("Error", entry[0], err)
482-
})
482+
if (w.length > i+1) {
483+
runTest(i+1)
483484
} else {
484-
entry[1](result)
485+
process.exit(fail ? 1 : 0)
485486
}
486-
})
487+
}
488+
if (entry[1].hasOwnProperty('then')) {
489+
entry[1](result).catch((err) => {
490+
fail = true
491+
console.error("> Error", entry[0], err)
492+
})
493+
} else {
494+
entry[1](result)
495+
}
496+
}
497+
498+
const runTests = () => {
499+
runTest(0)
487500
}
488501

489502
var httpServer = http.createServer(httpHandler).listen(5136, runTests)

0 commit comments

Comments
 (0)