Skip to content

Commit

Permalink
test(integration): close server synchronously (#4785)
Browse files Browse the repository at this point in the history
* chore: normalize afterAll

Signed-off-by: Logan McAnsh <logan@mcan.sh>

* test: close server synchronously

Signed-off-by: Logan McAnsh <logan@mcan.sh>

* chore: appFixture.close isnt async anymore

Signed-off-by: Logan McAnsh <logan@mcan.sh>

* Update integration/helpers/create-fixture.ts

Co-authored-by: Pedro Cattori <pcattori@gmail.com>

Signed-off-by: Logan McAnsh <logan@mcan.sh>
Co-authored-by: Pedro Cattori <pcattori@gmail.com>
  • Loading branch information
mcansh and pcattori committed Dec 9, 2022
1 parent b77ba74 commit 07c7dca
Show file tree
Hide file tree
Showing 30 changed files with 85 additions and 65 deletions.
4 changes: 3 additions & 1 deletion integration/abort-signal-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ test.beforeAll(async () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("should not abort the request in a new event loop", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
Expand Down
4 changes: 2 additions & 2 deletions integration/action-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ test.describe("actions", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

let logs: string[] = [];
Expand Down
4 changes: 3 additions & 1 deletion integration/bug-report-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ test.beforeAll(async () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

////////////////////////////////////////////////////////////////////////////////
// 💿 Almost done, now write your failing test case(s) down here Make sure to
Expand Down
4 changes: 3 additions & 1 deletion integration/catch-boundary-data-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ test.beforeAll(async () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("renders root boundary with data available", async () => {
let res = await fixture.requestDocument(NO_BOUNDARY_LOADER);
Expand Down
4 changes: 3 additions & 1 deletion integration/catch-boundary-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ test.describe("CatchBoundary", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("non-matching urls on document requests", async () => {
let res = await fixture.requestDocument(NOT_FOUND_HREF);
Expand Down
4 changes: 3 additions & 1 deletion integration/compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ test.describe("compiler", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("removes server code with `*.server` files", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
Expand Down
4 changes: 2 additions & 2 deletions integration/error-boundary-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ test.describe("ErrorBoundary", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
test.afterAll(() => {
console.error = _consoleError;
await appFixture.close();
appFixture.close();
});

test("invalid request methods", async () => {
Expand Down
4 changes: 2 additions & 2 deletions integration/error-data-request-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ test.describe("ErrorBoundary", () => {
errorLogs = [];
});

test.afterAll(async () => {
test.afterAll(() => {
console.error = _consoleError;
await appFixture.close();
appFixture.close();
});

function assertConsoleError(str: string) {
Expand Down
4 changes: 3 additions & 1 deletion integration/fetcher-layout-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ test.beforeAll(async () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("fetcher calls layout route action when at index route", async ({
page,
Expand Down
4 changes: 2 additions & 2 deletions integration/fetcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ test.describe("useFetcher", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test.describe("No JavaScript", () => {
Expand Down
4 changes: 2 additions & 2 deletions integration/file-uploads-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ test.describe("file-uploads", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("handles files under upload size limit", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions integration/form-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ test.describe("Forms", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test.describe("without JavaScript", () => {
Expand Down
18 changes: 6 additions & 12 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 @@ -130,10 +124,10 @@ export async function createAppFixture(fixture: Fixture, mode?: ServerMode) {
/**
* Shuts down the fixture app, **you need to call this
* at the end of a test** or `afterAll` if the fixture is initialized in a
* `beforeAll` block. Also make sure to `await app.close()` or else you'll
* `beforeAll` block. Also make sure to `app.close()` or else you'll
* have memory leaks.
*/
close: async () => {
close: () => {
return stop();
},
};
Expand Down
4 changes: 2 additions & 2 deletions integration/hook-useSubmit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ test.describe("`useSubmit()` returned function", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("submits the submitter's value appended to the form data", async ({
Expand Down
4 changes: 2 additions & 2 deletions integration/js-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ test.describe(".js route files", () => {
);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("should render all .js routes", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions integration/layout-route-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ test.describe("pathless layout routes", () => {
);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("should render pathless index route", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions integration/link-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ test.describe("route module link export", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("adds responsive image preload links to the document", async ({
Expand Down
4 changes: 2 additions & 2 deletions integration/loader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ test.describe("loader in an app", () => {
);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("sends a redirect", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions integration/mdx-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export function ComponentUsingData() {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("can render basic markdown", async ({ page }) => {
Expand Down
8 changes: 6 additions & 2 deletions integration/meta-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ test.describe("meta", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("empty meta does not render a tag", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
Expand Down Expand Up @@ -475,7 +477,9 @@ test.describe("v2_meta", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("empty meta does not render a tag", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
Expand Down
4 changes: 2 additions & 2 deletions integration/multiple-cookies-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ test.describe("pathless layout routes", () => {
);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("should get multiple cookies from the loader", async ({ page }) => {
Expand Down
16 changes: 9 additions & 7 deletions integration/prefetch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ test.describe("prefetch=none", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("does not render prefetch tags during SSR", async ({ page }) => {
let res = await fixture.requestDocument("/");
Expand All @@ -107,8 +109,8 @@ test.describe("prefetch=render", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("does not render prefetch tags during SSR", async ({ page }) => {
Expand Down Expand Up @@ -149,8 +151,8 @@ test.describe("prefetch=intent (hover)", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("does not render prefetch tags during SSR", async ({ page }) => {
Expand Down Expand Up @@ -220,8 +222,8 @@ test.describe("prefetch=intent (focus)", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("does not render prefetch tags during SSR", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions integration/redirects-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ test.describe("redirects", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("preserves revalidation across action multi-redirects", async ({
Expand Down
4 changes: 3 additions & 1 deletion integration/rendering-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ test.describe("rendering", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("server renders matching routes", async () => {
let res = await fixture.requestDocument("/");
Expand Down
4 changes: 2 additions & 2 deletions integration/resource-routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ test.describe("loader in an app", async () => {
appFixture = await createAppFixture(fixture, ServerMode.Test);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test.describe("with JavaScript", () => {
Expand Down
4 changes: 3 additions & 1 deletion integration/server-code-in-browser-message-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ test.beforeAll(async () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test.skip("should log relevant error message", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
Expand Down
4 changes: 3 additions & 1 deletion integration/set-cookie-revalidation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ test.beforeAll(async () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(() => appFixture.close());
test.afterAll(() => {
appFixture.close();
});

test("should revalidate when cookie is set on redirect from loader", async ({
page,
Expand Down
4 changes: 2 additions & 2 deletions integration/transition-state-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ test.describe("rendering", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("transitions to normal load (Loading)", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions integration/transition-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ test.describe("rendering", () => {
appFixture = await createAppFixture(fixture);
});

test.afterAll(async () => {
await appFixture.close();
test.afterAll(() => {
appFixture.close();
});

test("calls all loaders for new routes", async ({ page }) => {
Expand Down

0 comments on commit 07c7dca

Please sign in to comment.