Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code coverage #162

Merged
merged 11 commits into from
Oct 9, 2019
4 changes: 1 addition & 3 deletions src/processRequest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export const processRequest = (

currentStream = stream
stream.on('end', () => {
if (currentStream === stream) currentStream = null
currentStream = null
})

const upload = map.get(fieldName)
Expand All @@ -295,7 +295,6 @@ export const processRequest = (
})

stream.on('limit', () => {
if (currentStream === stream) currentStream = null
stream.unpipe()
capacitor.destroy(
createError(
Expand All @@ -306,7 +305,6 @@ export const processRequest = (
})

stream.on('error', error => {
if (currentStream === stream) currentStream = null
stream.unpipe()
capacitor.destroy(exitError || error)
})
Expand Down
17 changes: 14 additions & 3 deletions src/processRequest.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ t.test('Handles unconsumed uploads.', async t => {
})
})

t.test('Aborted request.', async t => {
t.only('Aborted request.', async t => {
mike-marcacci marked this conversation as resolved.
Show resolved Hide resolved
const sendRequest = (port, requestHasBeenReceived) =>
new Promise((resolve, reject) => {
const body = new FormData()
Expand Down Expand Up @@ -720,7 +720,7 @@ t.test('Aborted request.', async t => {
}

await t.test('Koa middleware.', async t => {
t.plan(5)
t.plan(6)

let requestHasBeenReceived
const requestHasBeenReceivedPromise = new Promise(
Expand Down Expand Up @@ -757,6 +757,9 @@ t.test('Aborted request.', async t => {
finish()
})

let appErrors = 0
app.on('error', () => appErrors++)
jaydenseric marked this conversation as resolved.
Show resolved Hide resolved

const port = await startServer(t, app)

await sendRequest(port, requestHasBeenReceivedPromise)
Expand All @@ -771,6 +774,8 @@ t.test('Aborted request.', async t => {
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')

await t.equals(appErrors, 1)
})

await t.test('Express middleware.', async t => {
Expand Down Expand Up @@ -851,7 +856,7 @@ t.test('Aborted request.', async t => {
}

await t.test('Koa middleware.', async t => {
t.plan(5)
t.plan(6)

let requestHasBeenReceived
const requestHasBeenReceivedPromise = new Promise(
Expand Down Expand Up @@ -893,7 +898,11 @@ t.test('Aborted request.', async t => {
finish()
})

let appErrors = 0
app.on('error', () => appErrors++)
jaydenseric marked this conversation as resolved.
Show resolved Hide resolved

const port = await startServer(t, app)

await sendRequest(port, requestHasBeenReceivedPromise)
await finished

Expand All @@ -906,6 +915,8 @@ t.test('Aborted request.', async t => {
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')

t.equals(appErrors, 1)
})

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