Skip to content

Commit 62a02a1

Browse files
Merge pull request #346 from preactjs/update-pentf
Update test deps
2 parents 79bec5f + 3904cc8 commit 62a02a1

30 files changed

+267
-144
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@
7373
"mkdirp": "^1.0.4",
7474
"mochette": "^1.0.1",
7575
"node-fetch": "^2.6.1",
76-
"pentf": "^3.2.3",
76+
"pentf": "^3.3.9",
7777
"preact": "^10.5.7",
7878
"prettier": "^2.1.2",
79-
"puppeteer": "^10.2.0",
79+
"puppeteer": "^14.0.0",
8080
"rimraf": "^3.0.2",
8181
"rollup": "^2.28.1",
8282
"rollup-plugin-copy": "^3.3.0",

test-e2e/test-utils.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { waitForPass } from "pentf/assert_utils";
2+
import { ignoreError } from "pentf/utils";
23
import { expect } from "chai";
4+
import { strict as assert } from "assert";
35
import {
46
clickNestedText,
57
clickTestId,
@@ -8,7 +10,6 @@ import {
810
waitForTestId,
911
resizePage,
1012
clickSelector,
11-
waitForSelector,
1213
} from "pentf/browser_utils";
1314
import { Page } from "puppeteer";
1415
import { getPreactVersions } from "./fixtures/utils";
@@ -18,6 +19,41 @@ export interface TestOptions {
1819
preact?: string;
1920
}
2021

22+
export async function waitForSelector(
23+
page: Page,
24+
selector: string,
25+
{ timeout = 5000, checkEvery = 200 } = {},
26+
) {
27+
let remainingTimeout = timeout;
28+
// eslint-disable-next-line no-constant-condition
29+
while (true) {
30+
let found = false;
31+
let errored = false;
32+
try {
33+
found = await page.evaluate(selector => {
34+
return !!document.querySelector(selector);
35+
}, selector);
36+
} catch (err) {
37+
errored = true;
38+
if (!ignoreError(err)) {
39+
throw err;
40+
}
41+
}
42+
43+
if (!errored && found) {
44+
break;
45+
}
46+
47+
if (remainingTimeout <= 0) {
48+
assert(found, `Element matching ${selector} is not found.`);
49+
break;
50+
}
51+
52+
await wait(Math.min(checkEvery, remainingTimeout));
53+
remainingTimeout -= checkEvery;
54+
}
55+
}
56+
2157
export async function newTestPage(
2258
config: any,
2359
name: string,
@@ -72,7 +108,7 @@ export async function getAttribute$$(
72108
selector: string,
73109
name: string,
74110
) {
75-
await page.waitForSelector(selector);
111+
await waitForSelector(page, selector);
76112
return page.$$eval(
77113
selector,
78114
(els: Element[], propName: any) => {
@@ -131,7 +167,7 @@ export async function waitForAttribute(
131167
}
132168

133169
export async function click(page: Page, selector: string) {
134-
await page.waitForSelector(selector);
170+
await waitForSelector(page, selector);
135171
return page.click(selector);
136172
}
137173

@@ -207,7 +243,7 @@ export async function clickTab(page: Page, tab: DevtoolsTab) {
207243
}
208244

209245
export async function getActiveTab(page: Page): Promise<DevtoolsTab> {
210-
await page.waitForSelector('input[name="root-panel"]');
246+
await waitForSelector(page, 'input[name="root-panel"]');
211247
return await page.evaluate(() => {
212248
const input = (Array.from(
213249
document.querySelectorAll('input[name="root-panel"]'),

test-e2e/tests/collapse.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { newTestPage, click, getLog, waitFor, clickTab } from "../test-utils";
1+
import {
2+
newTestPage,
3+
click,
4+
getLog,
5+
waitFor,
6+
clickTab,
7+
waitForSelector,
8+
} from "../test-utils";
29
import { expect } from "chai";
310
import { clickNestedText } from "pentf/browser_utils";
411

@@ -7,7 +14,7 @@ export const description = "Collapse all the things!";
714
export async function run(config: any) {
815
const { page, devtools } = await newTestPage(config, "update-all");
916

10-
await devtools.waitForSelector('[data-testid="tree-item"]', {
17+
await waitForSelector(devtools, '[data-testid="tree-item"]', {
1118
timeout: 1000,
1219
});
1320

@@ -31,7 +38,7 @@ export async function run(config: any) {
3138
// Props should be collapsed by default
3239
await clickNestedText(devtools, "Provider");
3340
const row = '[data-testid="props-row"]';
34-
await devtools.waitForSelector(row, {
41+
await waitForSelector(devtools, row, {
3542
timeout: 1000,
3643
});
3744

@@ -56,7 +63,7 @@ export async function run(config: any) {
5663

5764
// Switching to Profiler and back should not change collapse state
5865
await clickTab(devtools, "PROFILER");
59-
await devtools.waitForSelector('[data-testid="record-btn"]');
66+
await waitForSelector(devtools, '[data-testid="record-btn"]');
6067
await clickTab(devtools, "ELEMENTS");
6168

6269
// Our input should still be visible

test-e2e/tests/element-scroll.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { newTestPage, installMouseHelper } from "../test-utils";
1+
import {
2+
newTestPage,
3+
installMouseHelper,
4+
waitForSelector,
5+
} from "../test-utils";
26
import { expect } from "chai";
37
import { getText } from "pentf/browser_utils";
48

@@ -14,7 +18,7 @@ export async function run(config: any) {
1418
});
1519

1620
const selector = '[data-name="App"]';
17-
await devtools.waitForSelector(selector);
21+
await waitForSelector(devtools, selector);
1822
const { x, y } = await devtools.evaluate((s: string) => {
1923
const rect = document.querySelector(s)!.getBoundingClientRect();
2024
return { x: rect.right, y: rect.top };

test-e2e/tests/hoc-filter-disable.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { enableHOCFilter, newTestPage } from "../test-utils";
1+
import { enableHOCFilter, newTestPage, waitForSelector } from "../test-utils";
22
import { expect } from "chai";
33
import {
44
assertNotTestId,
@@ -18,7 +18,8 @@ export async function run(config: any) {
1818
await clickNestedText(devtools, "HOC-Components");
1919
await clickTestId(devtools, "filter-update");
2020

21-
await devtools.waitForSelector(
21+
await waitForSelector(
22+
devtools,
2223
'[data-testid="tree-item"][data-name="Memo(Foo)"]',
2324
);
2425

test-e2e/tests/hoc-filter-search.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { enableHOCFilter, newTestPage, typeText } from "../test-utils";
1+
import {
2+
enableHOCFilter,
3+
newTestPage,
4+
typeText,
5+
waitForSelector,
6+
} from "../test-utils";
27
import { expect } from "chai";
38
import { getText } from "pentf/browser_utils";
49
import { assertEventually } from "pentf/assert_utils";
@@ -8,7 +13,7 @@ export async function run(config: any) {
813
const { devtools } = await newTestPage(config, "hoc");
914
await enableHOCFilter(devtools);
1015

11-
await devtools.waitForSelector('[data-testid="tree-item"][data-name="Foo"]');
16+
await waitForSelector(devtools, '[data-testid="tree-item"][data-name="Foo"]');
1217
await typeText(devtools, '[data-testid="element-search"]', "forw");
1318

1419
let marked = await devtools.$$("mark");

test-e2e/tests/hoc-filter-update.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { enableHOCFilter, newTestPage } from "../test-utils";
1+
import { enableHOCFilter, newTestPage, waitForSelector } from "../test-utils";
22
import { expect } from "chai";
33
import { Page } from "puppeteer";
44

@@ -22,7 +22,8 @@ export async function run(config: any) {
2222
const { devtools, page } = await newTestPage(config, "hoc-update");
2323

2424
await enableHOCFilter(devtools);
25-
await devtools.waitForSelector(
25+
await waitForSelector(
26+
devtools,
2627
'[data-testid="tree-item"][data-name="Wrapped"]',
2728
);
2829

test-e2e/tests/hoc-filter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { enableHOCFilter, newTestPage } from "../test-utils";
1+
import { enableHOCFilter, newTestPage, waitForSelector } from "../test-utils";
22
import { expect } from "chai";
33
import { clickNestedText, waitForTestId } from "pentf/browser_utils";
44
import { waitForPass } from "pentf/assert_utils";
@@ -9,7 +9,7 @@ export async function run(config: any) {
99
const { devtools } = await newTestPage(config, "hoc");
1010
await enableHOCFilter(devtools);
1111

12-
await devtools.waitForSelector('[data-testid="tree-item"][data-name="Foo"]');
12+
await waitForSelector(devtools, '[data-testid="tree-item"][data-name="Foo"]');
1313

1414
const items = await devtools.evaluate(() => {
1515
return Array.from(
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { newTestPage, getHooks } from "../../test-utils";
1+
import { newTestPage, getHooks, waitForSelector } from "../../test-utils";
22
import { expect } from "chai";
33
import { clickNestedText } from "pentf/browser_utils";
44

@@ -15,40 +15,40 @@ export async function run(config: any) {
1515
return !!(await devtools.$('[data-testid="Hooks"]'));
1616
},
1717
});
18-
await devtools.waitForSelector(hooksPanel);
18+
await waitForSelector(devtools, hooksPanel);
1919

2020
expect(await getHooks(devtools)).to.deep.equal([
2121
["useState customState", "0"],
2222
]);
2323

2424
// Callback (Mixed)
2525
await clickNestedText(devtools, /CounterCallback$/);
26-
await devtools.waitForSelector(hooksPanel);
26+
await waitForSelector(devtools, hooksPanel);
2727
expect(await getHooks(devtools)).to.deep.equal([
2828
["useState counterState", "0"],
2929
["useCallback", "ƒ ()"],
3030
]);
3131

3232
// Reducer
3333
await clickNestedText(devtools, /ReducerComponent$/);
34-
await devtools.waitForSelector(hooksPanel);
34+
await waitForSelector(devtools, hooksPanel);
3535
expect(await getHooks(devtools)).to.deep.equal([
3636
["useReducer customReducer", '"foo"'],
3737
]);
3838

3939
// Ref
4040
await clickNestedText(devtools, /RefComponent$/);
41-
await devtools.waitForSelector(hooksPanel);
41+
await waitForSelector(devtools, hooksPanel);
4242
expect(await getHooks(devtools)).to.deep.equal([["useRef customRef", "0"]]);
4343

4444
// useMemo
4545
await clickNestedText(devtools, /MemoComponent$/);
46-
await devtools.waitForSelector(hooksPanel);
46+
await waitForSelector(devtools, hooksPanel);
4747
expect(await getHooks(devtools)).to.deep.equal([["useMemo customMemo", "0"]]);
4848

4949
// Multiple (test ordering)
5050
await clickNestedText(devtools, /^Multiple$/);
51-
await devtools.waitForSelector(hooksPanel);
51+
await waitForSelector(devtools, hooksPanel);
5252
expect(await getHooks(devtools)).to.deep.equal([
5353
["useState foo", "0"],
5454
["useState bar", "0"],
@@ -57,14 +57,14 @@ export async function run(config: any) {
5757

5858
// Do nothing for invalid callsites
5959
await clickNestedText(devtools, /CallbackOnly$/);
60-
await devtools.waitForSelector(hooksPanel);
60+
await waitForSelector(devtools, hooksPanel);
6161
expect(await getHooks(devtools)).to.deep.equal([["useCallback", "ƒ ()"]]);
6262

6363
await clickNestedText(devtools, /LayoutEffect$/);
64-
await devtools.waitForSelector(hooksPanel);
64+
await waitForSelector(devtools, hooksPanel);
6565
expect(await getHooks(devtools)).to.deep.equal([["useLayoutEffect", "ƒ ()"]]);
6666

6767
await clickNestedText(devtools, /^Effect$/);
68-
await devtools.waitForSelector(hooksPanel);
68+
await waitForSelector(devtools, hooksPanel);
6969
expect(await getHooks(devtools)).to.deep.equal([["useEffect", "ƒ ()"]]);
7070
}

test-e2e/tests/hooks/hooks-support.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { newTestPage } from "../../test-utils";
1+
import { newTestPage, waitForSelector } from "../../test-utils";
22
import { clickNestedText } from "pentf/browser_utils";
33

44
export const description =
@@ -13,5 +13,5 @@ export async function run(config: any) {
1313
await clickNestedText(devtools, "RefComponent");
1414

1515
// Should print warning
16-
await devtools.waitForSelector('[data-testid="no-hooks-support-warning"]');
16+
await waitForSelector(devtools, '[data-testid="no-hooks-support-warning"]');
1717
}

0 commit comments

Comments
 (0)