-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathabort-signal-test.ts
65 lines (54 loc) · 1.9 KB
/
abort-signal-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { test } from "@playwright/test";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import {
createAppFixture,
createFixture,
js,
} from "./helpers/create-fixture.js";
let fixture: Fixture;
let appFixture: AppFixture;
test.beforeAll(async () => {
fixture = await createFixture({
files: {
"app/routes/_index.tsx": js`
import { useActionData, useLoaderData, Form } from "react-router";
export async function action ({ request }) {
// New event loop causes express request to close
await new Promise(r => setTimeout(r, 0));
return { aborted: request.signal.aborted };
}
export function loader({ request }) {
return { aborted: request.signal.aborted };
}
export default function Index() {
let actionData = useActionData();
let data = useLoaderData();
return (
<div>
<p className="action">{actionData ? String(actionData.aborted) : "empty"}</p>
<p className="loader">{String(data.aborted)}</p>
<Form method="post">
<button type="submit">Submit</button>
</Form>
</div>
)
}
`,
},
});
// This creates an interactive app using playwright.
appFixture = await createAppFixture(fixture);
});
test.afterAll(() => {
appFixture.close();
});
test("should not abort the request in a new event loop", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await page.waitForSelector(`.action:has-text("empty")`);
await page.waitForSelector(`.loader:has-text("false")`);
await app.clickElement('button[type="submit"]');
await page.waitForSelector(`.action:has-text("false")`);
await page.waitForSelector(`.loader:has-text("false")`);
});