-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(handler): Always include the
data
field in stream messages (#71)
- Loading branch information
Showing
8 changed files
with
123 additions
and
2 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
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
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,36 @@ | ||
import net from 'net'; | ||
import http from 'http'; | ||
|
||
const leftovers: Dispose[] = []; | ||
afterAll(async () => { | ||
while (leftovers.length > 0) { | ||
await leftovers.pop()?.(); | ||
} | ||
}); | ||
|
||
export type Dispose = () => Promise<void>; | ||
|
||
export function startDisposableServer( | ||
server: http.Server, | ||
): [url: string, port: number, dispose: Dispose] { | ||
const sockets = new Set<net.Socket>(); | ||
server.on('connection', (socket) => { | ||
sockets.add(socket); | ||
socket.once('close', () => sockets.delete(socket)); | ||
}); | ||
|
||
const dispose = async () => { | ||
for (const socket of sockets) { | ||
socket.destroy(); | ||
} | ||
await new Promise<void>((resolve) => server.close(() => resolve())); | ||
}; | ||
leftovers.push(dispose); | ||
|
||
server.listen(0); | ||
|
||
const { port } = server.address() as net.AddressInfo; | ||
const url = `http://localhost:${port}`; | ||
|
||
return [url, port, dispose]; | ||
} |
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
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