Skip to content

Commit 25d317c

Browse files
authored
test(e2e): use page.waitForTimeout (#700)
1 parent eaa9ef8 commit 25d317c

File tree

11 files changed

+32
-75
lines changed

11 files changed

+32
-75
lines changed

packages/tests-e2e/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,30 @@ Their respective `packages/` are located at:
2222

2323
The GitHub actions will trigger the [e2e test](/.github/workflows//e2e.yml), which deploys the app in the [Example](/example/) folder. The deploy command is:
2424

25-
### Running the tests against the deployed app
25+
## Running the tests against the deployed app
2626

2727
1. Deploy the app
28+
2829
```bash
2930
cd examples/sst
3031
npx sst deploy --stage e2e
3132
```
33+
3234
2. Export the URLS
35+
3336
```bash
3437
export APP_ROUTER_URL=$(jq -r '.["e2e-example-AppRouter"].url' .sst/outputs.json)
3538
export PAGES_ROUTER_URL=$(jq -r '.["e2e-example-PagesRouter"].url' .sst/outputs.json)
3639
export APP_PAGES_ROUTER_URL=$(jq -r '.["e2e-example-AppPagesRouter"].url' .sst/outputs.json)
3740
```
41+
3842
3. Run the test
43+
3944
```bash
4045
cd ../../packages/tests-e2e
4146
pnpm run e2e:dev
4247
```
4348

44-
4549
## Gotchas
4650

4751
`isr.test.ts` returns a timestamp, when running `next dev`, ISR does not cache so each reload is a new timestamp. You'll need to `next build` and `next start` for Next to not cache.

packages/tests-e2e/tests/appPagesRouter/isr.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { wait } from "../utils";
4-
53
test("Incremental Static Regeneration", async ({ page }) => {
64
test.setTimeout(60000);
75
await page.goto("/");
@@ -14,7 +12,7 @@ test("Incremental Static Regeneration", async ({ page }) => {
1412
let newTime: typeof time;
1513
let tempTime = time;
1614
do {
17-
await wait(1000);
15+
await page.waitForTimeout(1000);
1816
await page.reload();
1917
time = tempTime;
2018
el = page.getByText("Time:");
@@ -23,17 +21,17 @@ test("Incremental Static Regeneration", async ({ page }) => {
2321
} while (time !== newTime);
2422
await page.reload();
2523

26-
await wait(1000);
24+
await page.waitForTimeout(1000);
2725
el = page.getByText("Time:");
2826
const midTime = await el.textContent();
2927
// Expect that the time is still stale
3028
expect(midTime).toEqual(newTime);
3129

3230
// Wait 10 + 1 seconds for ISR to regenerate time
33-
await wait(11000);
31+
await page.waitForTimeout(11000);
3432
let finalTime = newTime;
3533
do {
36-
await wait(2000);
34+
await page.waitForTimeout(2000);
3735
el = page.getByText("Time:");
3836
finalTime = await el.textContent();
3937
await page.reload();

packages/tests-e2e/tests/appPagesRouter/pages_isr.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { wait } from "../utils";
4-
53
test("Incremental Static Regeneration", async ({ page }) => {
64
test.setTimeout(60000);
75
await page.goto("/");
@@ -16,25 +14,25 @@ test("Incremental Static Regeneration", async ({ page }) => {
1614
let newTime: typeof time;
1715
let tempTime = time;
1816
do {
19-
await wait(1000);
17+
await page.waitForTimeout(1000);
2018
await page.reload();
2119
time = tempTime;
2220
el = page.getByText("Time:");
2321
newTime = await el.textContent();
2422
tempTime = newTime;
2523
} while (time !== newTime);
2624
await page.reload();
27-
await wait(1000);
25+
await page.waitForTimeout(1000);
2826
el = page.getByText("Time:");
2927
const midTime = await el.textContent();
3028
// Expect that the time is still stale
3129
expect(midTime).toEqual(newTime);
3230

3331
// Wait 10 + 1 seconds for ISR to regenerate time
34-
await wait(11000);
32+
await page.waitForTimeout(11000);
3533
let finalTime = newTime;
3634
do {
37-
await wait(2000);
35+
await page.waitForTimeout(2000);
3836
el = page.getByText("Time:");
3937
finalTime = await el.textContent();
4038
await page.reload();

packages/tests-e2e/tests/appPagesRouter/pages_ssr.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { wait } from "../utils";
4-
53
test("Server Side Render", async ({ page }) => {
64
await page.goto("/");
75
await page.locator('[href="/pages_ssr"]').click();
@@ -24,6 +22,6 @@ test("Server Side Render", async ({ page }) => {
2422
await expect(el).toBeVisible();
2523
expect(time).not.toEqual(newTime);
2624
time = newTime;
27-
await wait(250);
25+
await page.waitForTimeout(250);
2826
}
2927
});

packages/tests-e2e/tests/appPagesRouter/ssr.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { wait } from "../utils";
4-
53
test("Server Side Render", async ({ page }) => {
64
await page.goto("/");
75
await page.locator('[href="/ssr"]').click();
@@ -24,7 +22,7 @@ test("Server Side Render", async ({ page }) => {
2422
await expect(el).toBeVisible();
2523
expect(time).not.toEqual(newTime);
2624
time = newTime;
27-
await wait(250);
25+
await page.waitForTimeout(250);
2826
}
2927
});
3028

packages/tests-e2e/tests/appRouter/isr.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { wait } from "../utils";
4-
53
test("Incremental Static Regeneration", async ({ page }) => {
64
test.setTimeout(45000);
75
await page.goto("/");
@@ -14,7 +12,7 @@ test("Incremental Static Regeneration", async ({ page }) => {
1412
let newTime: typeof time;
1513
let tempTime = time;
1614
do {
17-
await wait(1000);
15+
await page.waitForTimeout(1000);
1816
await page.reload();
1917
time = tempTime;
2018
el = page.getByText("Time:");
@@ -23,17 +21,17 @@ test("Incremental Static Regeneration", async ({ page }) => {
2321
} while (time !== newTime);
2422
await page.reload();
2523

26-
await wait(1000);
24+
await page.waitForTimeout(1000);
2725
el = page.getByText("Time:");
2826
const midTime = await el.textContent();
2927
// Expect that the time is still stale
3028
expect(midTime).toEqual(newTime);
3129

3230
// Wait 10 + 1 seconds for ISR to regenerate time
33-
await wait(11000);
31+
await page.waitForTimeout(11000);
3432
let finalTime = newTime;
3533
do {
36-
await wait(2000);
34+
await page.waitForTimeout(2000);
3735
el = page.getByText("Time:");
3836
finalTime = await el.textContent();
3937
await page.reload();
@@ -56,7 +54,7 @@ test("headers", async ({ page }) => {
5654
if (headers["cache-control"] === "max-age=10, stale-while-revalidate=999") {
5755
break;
5856
}
59-
await wait(1000);
57+
await page.waitForTimeout(1000);
6058
responsePromise = page.waitForResponse((response) => {
6159
return response.status() === 200;
6260
});

packages/tests-e2e/tests/appRouter/sse.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import { expect, test } from "@playwright/test";
55

6-
import { wait } from "../utils";
7-
86
// NOTE: We don't await page load b/c we want to see the Loading page
97
test("Server Sent Events", async ({ page }) => {
108
await page.goto("/");
@@ -17,31 +15,31 @@ test("Server Sent Events", async ({ page }) => {
1715
// 2nd message shouldn't arrive yet
1816
let msg2 = page.getByText(`Message 2: {"message":"hello:2"`);
1917
await expect(msg2).not.toBeVisible();
20-
await wait(2000);
18+
await page.waitForTimeout(2000);
2119
// 2nd message should arrive after 2s
2220
msg2 = page.getByText(`Message 2: {"message":"hello:2"`);
2321
await expect(msg2).toBeVisible();
2422

2523
// 3rd message shouldn't arrive yet
2624
let msg3 = page.getByText(`Message 3: {"message":"hello:3"`);
2725
await expect(msg3).not.toBeVisible();
28-
await wait(2000);
26+
await page.waitForTimeout(2000);
2927
// 3rd message should arrive after 2s
3028
msg3 = page.getByText(`Message 3: {"message":"hello:3"`);
3129
await expect(msg3).toBeVisible();
3230

3331
// 4th message shouldn't arrive yet
3432
let msg4 = page.getByText(`Message 4: {"message":"hello:4"`);
3533
await expect(msg4).not.toBeVisible();
36-
await wait(2000);
34+
await page.waitForTimeout(2000);
3735
// 4th message should arrive after 2s
3836
msg4 = page.getByText(`Message 4: {"message":"hello:4"`);
3937
await expect(msg4).toBeVisible();
4038

4139
let close = page.getByText(`Message 5: {"message":"close"`);
4240
await expect(close).not.toBeVisible();
4341

44-
await wait(2000);
42+
await page.waitForTimeout(2000);
4543
close = page.getByText(`Message 5: {"message":"close"`);
4644
await expect(close).toBeVisible();
4745
});

packages/tests-e2e/tests/appRouter/ssr.test.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import { expect, test } from "@playwright/test";
55

6-
import { wait } from "../utils";
7-
86
// NOTE: We don't await page load b/c we want to see the Loading page
97
test("Server Side Render and loading.tsx", async ({ page }) => {
108
test.setTimeout(600000);
@@ -25,40 +23,14 @@ test("Server Side Render and loading.tsx", async ({ page }) => {
2523
const time = await el.textContent();
2624
expect(time).not.toEqual(lastTime);
2725
lastTime = time!;
28-
await wait(1000);
26+
await page.waitForTimeout(1000);
2927
}
30-
31-
// let loading = page.getByText("Loading...");
32-
// await expect(loading).toBeVisible();
33-
34-
// let el = page.getByText("Time:");
35-
// await expect(el).toBeVisible();
36-
// const time = await el.textContent();
37-
38-
// page.reload();
39-
// loading = page.getByText("Loading...");
40-
// await expect(loading).toBeVisible();
41-
42-
// el = page.getByText("Time:");
43-
// let newTime = await el.textContent();
44-
// await expect(el).toBeVisible();
45-
// await expect(time).not.toEqual(newTime);
46-
47-
// await wait(5000);
48-
// page.reload();
49-
// loading = page.getByText("Loading...");
50-
// await expect(loading).toBeVisible();
51-
52-
// el = page.getByText("Time:");
53-
// newTime = await el.textContent();
54-
// await expect(el).toBeVisible();
55-
// await expect(time).not.toEqual(newTime);
5628
});
5729

5830
test("Fetch cache properly cached", async ({ page }) => {
5931
await page.goto("/ssr");
6032
const originalDate = await page.getByText("Cached fetch:").textContent();
61-
await wait(2000);
33+
await page.waitForTimeout(2000);
6234
await page.reload();
6335
const newDate = await page.getByText("Cached fetch:").textContent();
6436
expect(originalDate).toEqual(newDate);

packages/tests-e2e/tests/pagesRouter/isr.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { wait } from "../utils";
4-
53
test("Incremental Static Regeneration", async ({ page }) => {
64
test.setTimeout(45000);
75
await page.goto("/");
@@ -15,25 +13,25 @@ test("Incremental Static Regeneration", async ({ page }) => {
1513
let newTime: typeof time;
1614
let tempTime = time;
1715
do {
18-
await wait(1000);
16+
await page.waitForTimeout(1000);
1917
await page.reload();
2018
time = tempTime;
2119
el = page.getByText("Time:");
2220
newTime = await el.textContent();
2321
tempTime = newTime;
2422
} while (time !== newTime);
2523
await page.reload();
26-
await wait(1000);
24+
await page.waitForTimeout(1000);
2725
el = page.getByText("Time:");
2826
const midTime = await el.textContent();
2927
// Expect that the time is still stale
3028
expect(midTime).toEqual(newTime);
3129

3230
// Wait 10 + 1 seconds for ISR to regenerate time
33-
await wait(11000);
31+
await page.waitForTimeout(11000);
3432
let finalTime = newTime;
3533
do {
36-
await wait(2000);
34+
await page.waitForTimeout(2000);
3735
el = page.getByText("Time:");
3836
finalTime = await el.textContent();
3937
await page.reload();

packages/tests-e2e/tests/pagesRouter/ssr.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from "@playwright/test";
22

3-
import { wait } from "../utils";
4-
53
test("Server Side Render", async ({ page }) => {
64
await page.goto("/");
75
await page.locator('[href="/ssr/"]').click();
@@ -24,7 +22,7 @@ test("Server Side Render", async ({ page }) => {
2422
await expect(el).toBeVisible();
2523
expect(time).not.toEqual(newTime);
2624
time = newTime;
27-
await wait(250);
25+
await page.waitForTimeout(250);
2826
}
2927
});
3028

0 commit comments

Comments
 (0)