Skip to content

Commit b8f0975

Browse files
authored
Merge pull request #132 from jaydenseric/fix/131
Update fs-capacitor and corresponding tests, fixes #131 .
2 parents 587c5d2 + ad47be7 commit b8f0975

File tree

3 files changed

+75
-29
lines changed

3 files changed

+75
-29
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# graphql-upload changelog
22

3+
## Next
4+
5+
### Patch
6+
7+
- 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+
39
## 8.0.3
410

511
### Patch

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"dependencies": {
3939
"busboy": "^0.3.0",
40-
"fs-capacitor": "^1.0.0",
40+
"fs-capacitor": "^2.0.0",
4141
"http-errors": "^1.7.1",
4242
"object-path": "^0.11.4"
4343
},

src/test.mjs

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ t.test('Single file.', async t => {
119119
await sendRequest(port)
120120

121121
const file = await variables.file
122-
await new Promise(resolve => file.capacitor.once('close', resolve))
122+
if (!file.capacitor.closed)
123+
await new Promise(resolve => file.capacitor.once('close', resolve))
123124
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
124125
})
125126

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

144145
const file = await variables.file
145-
await new Promise(resolve => file.capacitor.once('close', resolve))
146+
if (!file.capacitor.closed)
147+
await new Promise(resolve => file.capacitor.once('close', resolve))
146148
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
147149
})
148150
})
@@ -308,11 +310,13 @@ t.test('Handles unconsumed uploads.', async t => {
308310
await sendRequest(port)
309311

310312
const fileA = await variables.fileA
311-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
313+
if (!fileA.capacitor.closed)
314+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
312315
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
313316

314317
const fileB = await variables.fileB
315-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
318+
if (!fileB.capacitor.closed)
319+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
316320
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
317321
})
318322

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

338342
const fileA = await variables.fileA
339-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
343+
if (!fileA.capacitor.closed)
344+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
340345
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
341346

342347
const fileB = await variables.fileB
343-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
348+
if (!fileB.capacitor.closed)
349+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
344350
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
345351
})
346352
})
@@ -443,6 +449,18 @@ t.test('Aborted request.', async t => {
443449

444450
const uploadBTest = (file, stream) => async t => {
445451
await new Promise(resolve => {
452+
if (stream.error) {
453+
t.matchSnapshot(snapshotError(stream.error), 'Stream error.')
454+
resolve()
455+
return
456+
}
457+
458+
if (stream.ended) {
459+
t.fail('File shouldn’t fully upload.')
460+
resolve()
461+
return
462+
}
463+
446464
stream
447465
.on('error', error => {
448466
t.matchSnapshot(snapshotError(error), 'Stream error.')
@@ -498,11 +516,13 @@ t.test('Aborted request.', async t => {
498516
await finished
499517

500518
const fileA = await variables.fileA
501-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
519+
if (!fileA.capacitor.closed)
520+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
502521
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
503522

504523
const fileB = await variables.fileB
505-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
524+
if (!fileB.capacitor.closed)
525+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
506526
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
507527
})
508528

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

549569
const fileA = await variables.fileA
550-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
570+
if (!fileA.capacitor.closed)
571+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
551572
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
552573

553574
const fileB = await variables.fileB
554-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
575+
if (!fileB.capacitor.closed)
576+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
555577
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
556578
})
557579
})
@@ -625,11 +647,13 @@ t.test('Aborted request.', async t => {
625647
await finished
626648

627649
const fileA = await variables.fileA
628-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
650+
if (!fileA.capacitor.closed)
651+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
629652
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
630653

631654
const fileB = await variables.fileB
632-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
655+
if (!fileB.capacitor.closed)
656+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
633657
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
634658
})
635659

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

680704
const fileA = await variables.fileA
681-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
705+
if (!fileA.capacitor.closed)
706+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
682707
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
683708

684709
const fileB = await variables.fileB
685-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
710+
if (!fileB.capacitor.closed)
711+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
686712
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
687713
})
688714
})
@@ -759,11 +785,13 @@ t.test('Deduped files.', async t => {
759785
await sendRequest(port)
760786

761787
const fileA = await variables.files[0]
762-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
788+
if (!fileA.capacitor.closed)
789+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
763790
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
764791

765792
const fileB = await variables.files[1]
766-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
793+
if (!fileB.capacitor.closed)
794+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
767795
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
768796
})
769797

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

807835
const fileA = await variables.files[0]
808-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
836+
if (!fileA.capacitor.closed)
837+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
809838
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
810839

811840
const fileB = await variables.files[1]
812-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
841+
if (!fileB.capacitor.closed)
842+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
813843
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
814844
})
815845
})
@@ -930,7 +960,8 @@ t.test('Extraneous file.', async t => {
930960
await sendRequest(port)
931961

932962
const file = await variables.file
933-
await new Promise(resolve => file.capacitor.once('close', resolve))
963+
if (!file.capacitor.closed)
964+
await new Promise(resolve => file.capacitor.once('close', resolve))
934965
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
935966
})
936967

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

955986
const file = await variables.file
956-
await new Promise(resolve => file.capacitor.once('close', resolve))
987+
if (!file.capacitor.closed)
988+
await new Promise(resolve => file.capacitor.once('close', resolve))
957989
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
958990
})
959991
})
@@ -1095,7 +1127,8 @@ t.test('Exceed max files with extraneous files interspersed.', async t => {
10951127
await finished
10961128

10971129
const fileA = await variables.files[0]
1098-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
1130+
if (!fileA.capacitor.closed)
1131+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
10991132
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
11001133
})
11011134

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

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

12001234
const fileA = await variables.files[0]
1201-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
1235+
if (!fileA.capacitor.closed)
1236+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
12021237
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
12031238

12041239
const fileB = await variables.files[1]
1205-
await new Promise(resolve => fileB.capacitor.once('close', resolve))
1240+
if (!fileB.capacitor.closed)
1241+
await new Promise(resolve => fileB.capacitor.once('close', resolve))
12061242
t.false(fs.existsSync(fileB.capacitor.path), 'Cleanup B.')
12071243
})
12081244

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

12291265
const fileA = await variables.files[0]
1230-
await new Promise(resolve => fileA.capacitor.once('close', resolve))
1266+
if (!fileA.capacitor.closed)
1267+
await new Promise(resolve => fileA.capacitor.once('close', resolve))
12311268
t.false(fs.existsSync(fileA.capacitor.path), 'Cleanup A.')
12321269

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

15201558
const file = await variables.file
1521-
await new Promise(resolve => file.capacitor.once('close', resolve))
1559+
if (!file.capacitor.closed)
1560+
await new Promise(resolve => file.capacitor.once('close', resolve))
15221561
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
15231562
})
15241563

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

15431582
const file = await variables.file
1544-
await new Promise(resolve => file.capacitor.once('close', resolve))
1583+
if (!file.capacitor.closed)
1584+
await new Promise(resolve => file.capacitor.once('close', resolve))
15451585
t.false(fs.existsSync(file.capacitor.path), 'Cleanup.')
15461586
})
15471587
})

0 commit comments

Comments
 (0)