Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remix Test #644

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/example-pages-functions-app/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { spawn } from "child_process";
import { resolve } from "path";
import { fetch } from "undici";
import type { ChildProcess } from "child_process";
import type { Response } from "undici";

const waitUntilReady = async (url: string): Promise<Response> => {
let response: Response | undefined = undefined;

while (response === undefined) {
await new Promise((resolvePromise) => setTimeout(resolvePromise, 500));

try {
response = await fetch(url);
} catch {}
}
const container = await new Promise((resolvePromise) => {
const closedLoop = setTimeout(async () => {
const response = await fetch(url);
if (response.status === 200) {
clearTimeout(closedLoop);
resolvePromise(response);
}
}, 1500);
});

return response as Response;
await new Promise(process.nextTick); // flushes previous Promises in the event loop
return (await container) as Response;
};

const isWindows = process.platform === "win32";

describe("Remix", () => {
let wranglerProcess: ChildProcess | undefined;
beforeAll(async () => {
const wranglerProcess = spawn("npm", ["run", "dev"], {
wranglerProcess = spawn("npm", ["run", "dev"], {
shell: isWindows,
cwd: resolve(__dirname, "../"),
env: { BROWSER: "none", ...process.env },
Expand All @@ -33,6 +36,11 @@ describe("Remix", () => {
console.log(chunk.toString());
});
});
afterAll(async () => {
if (wranglerProcess) {
wranglerProcess.kill();
}
});

it("renders static pages", async () => {
const response = await waitUntilReady("http://localhost:8789/");
Expand Down