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

Update fs-capacitor and corresponding tests #132

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# graphql-upload changelog

## Next

### Patch

- Updated the [`fs-capacitor`](https://npm.im/fs-capacitor) dependency to v2, fixing [#131](https://github.com/jaydenseric/graphql-upload/issues/131) via [#132](https://github.com/jaydenseric/graphql-upload/pull/132).

## 8.0.3

### Patch
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"busboy": "^0.3.0",
"fs-capacitor": "^1.0.0",
"fs-capacitor": "^2.0.0",
"http-errors": "^1.7.1",
"object-path": "^0.11.4"
},
Expand Down
96 changes: 68 additions & 28 deletions src/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ t.test('Single file.', async t => {
await sendRequest(port)

const file = await variables.file
await new Promise(resolve => file.capacitor.once('close', resolve))
if (!file.capacitor.closed)
await new Promise(resolve => file.capacitor.once('close', resolve))
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
})

Expand All @@ -142,7 +143,8 @@ t.test('Single file.', async t => {
await sendRequest(port)

const file = await variables.file
await new Promise(resolve => file.capacitor.once('close', resolve))
if (!file.capacitor.closed)
await new Promise(resolve => file.capacitor.once('close', resolve))
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
})
})
Expand Down Expand Up @@ -308,11 +310,13 @@ t.test('Handles unconsumed uploads.', async t => {
await sendRequest(port)

const fileA = await variables.fileA
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.fileB
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})

Expand All @@ -336,11 +340,13 @@ t.test('Handles unconsumed uploads.', async t => {
await sendRequest(port)

const fileA = await variables.fileA
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.fileB
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})
})
Expand Down Expand Up @@ -443,6 +449,18 @@ t.test('Aborted request.', async t => {

const uploadBTest = (file, stream) => async t => {
await new Promise(resolve => {
if (stream.error) {
t.matchSnapshot(snapshotError(stream.error), 'Stream error.')
resolve()
return
}

if (stream.ended) {
t.fail('File shouldn’t fully upload.')
resolve()
return
}

stream
.on('error', error => {
t.matchSnapshot(snapshotError(error), 'Stream error.')
Expand Down Expand Up @@ -498,11 +516,13 @@ t.test('Aborted request.', async t => {
await finished

const fileA = await variables.fileA
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.fileB
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})

Expand Down Expand Up @@ -547,11 +567,13 @@ t.test('Aborted request.', async t => {
await finished

const fileA = await variables.fileA
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.fileB
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})
})
Expand Down Expand Up @@ -625,11 +647,13 @@ t.test('Aborted request.', async t => {
await finished

const fileA = await variables.fileA
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.fileB
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})

Expand Down Expand Up @@ -678,11 +702,13 @@ t.test('Aborted request.', async t => {
await finished

const fileA = await variables.fileA
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.fileB
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})
})
Expand Down Expand Up @@ -759,11 +785,13 @@ t.test('Deduped files.', async t => {
await sendRequest(port)

const fileA = await variables.files[0]
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.files[1]
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})

Expand Down Expand Up @@ -805,11 +833,13 @@ t.test('Deduped files.', async t => {
await sendRequest(port)

const fileA = await variables.files[0]
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.files[1]
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})
})
Expand Down Expand Up @@ -930,7 +960,8 @@ t.test('Extraneous file.', async t => {
await sendRequest(port)

const file = await variables.file
await new Promise(resolve => file.capacitor.once('close', resolve))
if (!file.capacitor.closed)
await new Promise(resolve => file.capacitor.once('close', resolve))
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
})

Expand All @@ -953,7 +984,8 @@ t.test('Extraneous file.', async t => {
await sendRequest(port)

const file = await variables.file
await new Promise(resolve => file.capacitor.once('close', resolve))
if (!file.capacitor.closed)
await new Promise(resolve => file.capacitor.once('close', resolve))
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
})
})
Expand Down Expand Up @@ -1095,7 +1127,8 @@ t.test('Exceed max files with extraneous files interspersed.', async t => {
await finished

const fileA = await variables.files[0]
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
})

Expand All @@ -1119,7 +1152,8 @@ t.test('Exceed max files with extraneous files interspersed.', async t => {
await sendRequest(port)

const fileA = await variables.files[0]
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
})
})
Expand Down Expand Up @@ -1198,11 +1232,13 @@ t.test('Exceed max file size.', async t => {
await sendRequest(port)

const fileA = await variables.files[0]
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.files[1]
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})

Expand All @@ -1227,11 +1263,13 @@ t.test('Exceed max file size.', async t => {
await sendRequest(port)

const fileA = await variables.files[0]
await new Promise(resolve => fileA.capacitor.once('close', resolve))
if (!fileA.capacitor.closed)
await new Promise(resolve => fileA.capacitor.once('close', resolve))
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')

const fileB = await variables.files[1]
await new Promise(resolve => fileB.capacitor.once('close', resolve))
if (!fileB.capacitor.closed)
await new Promise(resolve => fileB.capacitor.once('close', resolve))
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
})
})
Expand Down Expand Up @@ -1518,7 +1556,8 @@ t.test('Deprecated file upload ‘stream’ property.', async t => {
await sendRequest(port)

const file = await variables.file
await new Promise(resolve => file.capacitor.once('close', resolve))
if (!file.capacitor.closed)
await new Promise(resolve => file.capacitor.once('close', resolve))
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
})

Expand All @@ -1541,7 +1580,8 @@ t.test('Deprecated file upload ‘stream’ property.', async t => {
await sendRequest(port)

const file = await variables.file
await new Promise(resolve => file.capacitor.once('close', resolve))
if (!file.capacitor.closed)
await new Promise(resolve => file.capacitor.once('close', resolve))
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
})
})