Skip to content

Commit

Permalink
test: close server synchronously
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh committed Dec 8, 2022
1 parent 5043b91 commit a1515a6
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions integration/helpers/create-fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import type { Writable } from "node:stream";
import path from "node:path";
import fse from "fs-extra";
import type { Writable } from "stream";
import express from "express";
import getPort from "get-port";
import stripIndent from "strip-indent";
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function createFixture(init: FixtureInit) {
export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
let startAppServer = async (): Promise<{
port: number;
stop: () => Promise<void>;
stop: VoidFunction;
}> => {
return new Promise(async (accept) => {
let port = await getPort();
Expand All @@ -110,13 +110,7 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {

let server = app.listen(port);

let stop = (): Promise<void> => {
return new Promise((res) => {
server.close(() => res());
});
};

accept({ stop, port });
accept({ stop: server.close.bind(server), port });
});
};

Expand All @@ -134,7 +128,11 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
* have memory leaks.
*/
close: async () => {
return stop();
try {
return stop();
} catch (error) {
throw error;
}
},
};
};
Expand Down

0 comments on commit a1515a6

Please sign in to comment.