-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: IncomingForm end event emitted twice (#852)
* fix: IncomingForm end event emitted twice * tests: add test for end emitted once * tests: change old test Co-authored-by: Cyril Walle <cyril.walle@protonmail.com>
- Loading branch information
1 parent
21efa7d
commit 92df3c8
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {strictEqual} from 'node:assert'; | ||
import { createServer } from 'node:http'; | ||
import { connect } from 'node:net'; | ||
import formidable from '../../src/index.js'; | ||
|
||
const PORT = 13539; | ||
|
||
test('end event emitted twice', (done) => { | ||
const server = createServer((req) => { | ||
const form = formidable(); | ||
|
||
let i = 0; | ||
form.on('end', () => { | ||
i += 1; | ||
strictEqual(i, 1, 'end should be emitted once'); | ||
}); | ||
form.parse(req, () => { | ||
|
||
server.close(); | ||
strictEqual(i, 1, 'end should be emitted once'); | ||
done(); | ||
}); | ||
}); | ||
|
||
server.listen(PORT, 'localhost', () => { | ||
const choosenPort = server.address().port; | ||
|
||
const client = connect(choosenPort); | ||
|
||
client.write( | ||
`POST /api/upload HTTP/1.1 | ||
Host: localhost:${choosenPort} | ||
User-Agent: N | ||
Content-Type: multipart/form-data; boundary=---------------------------13068458571765726332503797717 | ||
-----------------------------13068458571765726332503797717 | ||
Content-Disposition: form-data; name="title" | ||
a | ||
-----------------------------13068458571765726332503797717 | ||
Content-Disposition: form-data; name="multipleFiles"; filename="x.txt" | ||
Content-Type: application/x-javascript | ||
a | ||
b | ||
c | ||
d | ||
-----------------------------13068458571765726332503797717-- | ||
`, | ||
); | ||
client.end(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters