Skip to content

Commit a341dc1

Browse files
committed
Fix #130 - Error in test logs
I narrowed down these tests to aborting in a Koa app. This happened because: 1. Koa listens for the error event on the HTTP stream itself, and re-emits it on the app's own event emitter. 2. If there is no listener for an app error, Koa will deviate from the node default of crashing, and will instead log the error. 3. This particular error originates from within the HTTP stream, causing Koa to log the error message. I fixed this by actually _expecting_ one error to be emit from the app, adding an assertion to test this.
1 parent 46c9513 commit a341dc1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/processRequest.test.mjs

+14-3
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ t.test('Handles unconsumed uploads.', async t => {
608608
})
609609
})
610610

611-
t.test('Aborted request.', async t => {
611+
t.only('Aborted request.', async t => {
612612
const sendRequest = (port, requestHasBeenReceived) =>
613613
new Promise((resolve, reject) => {
614614
const body = new FormData()
@@ -720,7 +720,7 @@ t.test('Aborted request.', async t => {
720720
}
721721

722722
await t.test('Koa middleware.', async t => {
723-
t.plan(5)
723+
t.plan(6)
724724

725725
let requestHasBeenReceived
726726
const requestHasBeenReceivedPromise = new Promise(
@@ -757,6 +757,9 @@ t.test('Aborted request.', async t => {
757757
finish()
758758
})
759759

760+
let appErrors = 0
761+
app.on('error', () => appErrors++)
762+
760763
const port = await startServer(t, app)
761764

762765
await sendRequest(port, requestHasBeenReceivedPromise)
@@ -771,6 +774,8 @@ t.test('Aborted request.', async t => {
771774
if (!fileB.capacitor.closed)
772775
await new Promise(resolve => fileB.capacitor.once('close', resolve))
773776
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
777+
778+
await t.equals(appErrors, 1)
774779
})
775780

776781
await t.test('Express middleware.', async t => {
@@ -851,7 +856,7 @@ t.test('Aborted request.', async t => {
851856
}
852857

853858
await t.test('Koa middleware.', async t => {
854-
t.plan(5)
859+
t.plan(6)
855860

856861
let requestHasBeenReceived
857862
const requestHasBeenReceivedPromise = new Promise(
@@ -893,7 +898,11 @@ t.test('Aborted request.', async t => {
893898
finish()
894899
})
895900

901+
let appErrors = 0
902+
app.on('error', () => appErrors++)
903+
896904
const port = await startServer(t, app)
905+
897906
await sendRequest(port, requestHasBeenReceivedPromise)
898907
await finished
899908

@@ -906,6 +915,8 @@ t.test('Aborted request.', async t => {
906915
if (!fileB.capacitor.closed)
907916
await new Promise(resolve => fileB.capacitor.once('close', resolve))
908917
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
918+
919+
t.equals(appErrors, 1)
909920
})
910921

911922
await t.test('Express middleware.', async t => {

0 commit comments

Comments
 (0)