Skip to content

Commit d70caca

Browse files
Merge pull request #17915 from timvandermeij/lint-waitfortimeout
Implement a linting rule to discourage using `waitForTimeout` for new usages
2 parents f3b03e5 + d4633ba commit d70caca

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

test/integration/.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": [
3+
"../.eslintrc"
4+
],
5+
6+
"rules": {
7+
"no-restricted-syntax": ["error",
8+
{
9+
"selector": "CallExpression[callee.name='waitForTimeout']",
10+
"message": "`waitForTimeout` can cause intermittent failures and should not be used (see issue #17656 for replacements).",
11+
},
12+
],
13+
},
14+
}

test/integration/annotation_spec.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ describe("Checkbox annotation", () => {
170170
);
171171
for (const selector of selectors) {
172172
await page.click(selector);
173+
// eslint-disable-next-line no-restricted-syntax
173174
await waitForTimeout(10);
174175
}
175176
for (const selector of selectors) {
@@ -229,6 +230,7 @@ describe("Text widget", () => {
229230
pages.map(async ([browserName, page]) => {
230231
await page.type(getSelector("22R"), "a");
231232
await page.keyboard.press("Tab");
233+
// eslint-disable-next-line no-restricted-syntax
232234
await waitForTimeout(10);
233235

234236
const text = await page.$eval(getSelector("22R"), el => el.value);
@@ -515,11 +517,13 @@ describe("ResetForm action", () => {
515517
`document.querySelector("[data-annotation-id='25R']").hidden === false`
516518
);
517519
await page.click("#editorFreeText");
520+
// eslint-disable-next-line no-restricted-syntax
518521
await waitForTimeout(10);
519522
await page.waitForFunction(
520523
`document.querySelector("[data-annotation-id='25R']").hidden === true`
521524
);
522525
await page.click("#editorFreeText");
526+
// eslint-disable-next-line no-restricted-syntax
523527
await waitForTimeout(10);
524528
await page.waitForFunction(
525529
`document.querySelector("[data-annotation-id='25R']").hidden === false`
@@ -583,6 +587,7 @@ describe("ResetForm action", () => {
583587
expect(hidden).withContext(`In ${browserName}`).toEqual(true);
584588
await page.focus("[data-annotation-id='20R']");
585589
await page.keyboard.press("Enter");
590+
// eslint-disable-next-line no-restricted-syntax
586591
await waitForTimeout(10);
587592
hidden = await page.$eval(
588593
"[data-annotation-id='21R']",
@@ -591,6 +596,7 @@ describe("ResetForm action", () => {
591596
expect(hidden).withContext(`In ${browserName}`).toEqual(false);
592597

593598
await page.keyboard.press("Enter");
599+
// eslint-disable-next-line no-restricted-syntax
594600
await waitForTimeout(10);
595601
hidden = await page.$eval(
596602
"[data-annotation-id='21R']",
@@ -599,6 +605,7 @@ describe("ResetForm action", () => {
599605
expect(hidden).withContext(`In ${browserName}`).toEqual(true);
600606

601607
await page.keyboard.press("Enter");
608+
// eslint-disable-next-line no-restricted-syntax
602609
await waitForTimeout(10);
603610
hidden = await page.$eval(
604611
"[data-annotation-id='21R']",
@@ -607,6 +614,7 @@ describe("ResetForm action", () => {
607614
expect(hidden).withContext(`In ${browserName}`).toEqual(false);
608615

609616
await page.keyboard.press("Escape");
617+
// eslint-disable-next-line no-restricted-syntax
610618
await waitForTimeout(10);
611619
hidden = await page.$eval(
612620
"[data-annotation-id='21R']",

test/integration/freetext_editor_spec.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const copyPaste = async page => {
5656
await kbCopy(page);
5757
await promise;
5858

59+
// eslint-disable-next-line no-restricted-syntax
5960
await waitForTimeout(10);
6061

6162
promise = waitForEvent(page, "paste");
@@ -1147,6 +1148,7 @@ describe("FreeText Editor", () => {
11471148
await kbUndo(page);
11481149
// Nothing should happen, it's why we can't wait for something
11491150
// specific!
1151+
// eslint-disable-next-line no-restricted-syntax
11501152
await waitForTimeout(200);
11511153

11521154
// We check that the editor hasn't been removed.
@@ -1353,6 +1355,7 @@ describe("FreeText Editor", () => {
13531355
// Enter in editing mode.
13541356
await switchToFreeText(page);
13551357

1358+
// eslint-disable-next-line no-restricted-syntax
13561359
await waitForTimeout(200);
13571360

13581361
// Disable editing mode.
@@ -2399,6 +2402,7 @@ describe("FreeText Editor", () => {
23992402

24002403
// The editor must be moved in the DOM and potentially the focus
24012404
// will be lost, hence there's a callback will get back the focus.
2405+
// eslint-disable-next-line no-restricted-syntax
24022406
await waitForTimeout(200);
24032407

24042408
const focused = await page.evaluate(sel => {
@@ -3656,6 +3660,7 @@ describe("FreeText Editor", () => {
36563660
);
36573661

36583662
// Nothing should change, so it's hard to wait on something.
3663+
// eslint-disable-next-line no-restricted-syntax
36593664
await waitForTimeout(100);
36603665

36613666
text = await getText(editorSelector);
@@ -3677,6 +3682,7 @@ describe("FreeText Editor", () => {
36773682
);
36783683

36793684
// Nothing should change, so it's hard to wait on something.
3685+
// eslint-disable-next-line no-restricted-syntax
36803686
await waitForTimeout(100);
36813687

36823688
const html = await getHTML();

test/integration/scripting_spec.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,7 @@ describe("Interaction", () => {
17131713
await clearInput(page, getSelector("27R"));
17141714
await page.type(getSelector("27R"), exportValue);
17151715
await page.click("[data-annotation-id='28R']");
1716+
// eslint-disable-next-line no-restricted-syntax
17161717
await waitForTimeout(10);
17171718

17181719
value = await page.$eval(getSelector("24R"), el => el.value);
@@ -1760,6 +1761,7 @@ describe("Interaction", () => {
17601761
await page.waitForFunction(
17611762
`${getQuerySelector("30R")}.value !== "abc"`
17621763
);
1764+
// eslint-disable-next-line no-restricted-syntax
17631765
await waitForTimeout(100);
17641766

17651767
const focusedId = await page.evaluate(_ =>
@@ -1856,6 +1858,7 @@ describe("Interaction", () => {
18561858
expect(text).withContext(`In ${browserName}`).toEqual("00000000123");
18571859

18581860
await page.click(getSelector("26R"));
1861+
// eslint-disable-next-line no-restricted-syntax
18591862
await waitForTimeout(10);
18601863

18611864
text = await page.$eval(getSelector("25R"), el => el.value);
@@ -1890,12 +1893,14 @@ describe("Interaction", () => {
18901893
expect(text).withContext(`In ${browserName}`).toEqual("5,25");
18911894

18921895
await page.click(getSelector("22R"));
1896+
// eslint-disable-next-line no-restricted-syntax
18931897
await waitForTimeout(10);
18941898

18951899
text = await page.$eval(getSelector("22R"), el => el.value);
18961900
expect(text).withContext(`In ${browserName}`).toEqual("5,25");
18971901

18981902
await page.click(getSelector("31R"));
1903+
// eslint-disable-next-line no-restricted-syntax
18991904
await waitForTimeout(10);
19001905

19011906
text = await page.$eval(getSelector("31R"), el => el.value);
@@ -1927,6 +1932,7 @@ describe("Interaction", () => {
19271932
expect(text).withContext(`In ${browserName}`).toEqual("");
19281933

19291934
await page.select(getSelector("6R"), "Yes");
1935+
// eslint-disable-next-line no-restricted-syntax
19301936
await waitForTimeout(10);
19311937

19321938
text = await page.$eval(getSelector("44R"), el => el.value);
@@ -1935,6 +1941,7 @@ describe("Interaction", () => {
19351941
await clearInput(page, getSelector("44R"));
19361942

19371943
await page.select(getSelector("6R"), "No");
1944+
// eslint-disable-next-line no-restricted-syntax
19381945
await waitForTimeout(10);
19391946

19401947
text = await page.$eval(getSelector("44R"), el => el.value);
@@ -1992,13 +1999,15 @@ describe("Interaction", () => {
19921999
await page.type(getSelector("26R"), "abcde", { delay: 10 });
19932000

19942001
await page.click(getSelector("23R"));
2002+
// eslint-disable-next-line no-restricted-syntax
19952003
await waitForTimeout(10);
19962004
await page.click(getSelector("26R"));
19972005

19982006
await kbSelectAll(page);
19992007
await page.keyboard.press("Backspace");
20002008

20012009
await page.click(getSelector("23R"));
2010+
// eslint-disable-next-line no-restricted-syntax
20022011
await waitForTimeout(10);
20032012

20042013
text = await page.$eval(getSelector("26R"), el => el.value);
@@ -2095,6 +2104,7 @@ describe("Interaction", () => {
20952104
expect(visibility).withContext(`In ${browserName}`).toEqual("hidden");
20962105

20972106
await page.click(getSelector("11R"));
2107+
// eslint-disable-next-line no-restricted-syntax
20982108
await waitForTimeout(10);
20992109

21002110
visibility = await page.$eval(
@@ -2141,27 +2151,32 @@ describe("Interaction", () => {
21412151
);
21422152
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
21432153
await page.click(getSelector("334R"));
2154+
// eslint-disable-next-line no-restricted-syntax
21442155
await waitForTimeout(10);
21452156

21462157
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
21472158
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
21482159
await page.click(getSelector("351R"));
2160+
// eslint-disable-next-line no-restricted-syntax
21492161
await waitForTimeout(10);
21502162

21512163
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
21522164
expect(readonly).withContext(`In ${browserName}`).toEqual(true);
21532165
await page.click(getSelector("352R"));
2166+
// eslint-disable-next-line no-restricted-syntax
21542167
await waitForTimeout(10);
21552168

21562169
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
21572170
expect(readonly).withContext(`In ${browserName}`).toEqual(false);
21582171

21592172
await page.click(getSelector("353R"));
2173+
// eslint-disable-next-line no-restricted-syntax
21602174
await waitForTimeout(10);
21612175

21622176
let checked = await page.$eval(getSelector("353R"), el => el.checked);
21632177
expect(checked).withContext(`In ${browserName}`).toEqual(true);
21642178
await page.click(getSelector("334R"));
2179+
// eslint-disable-next-line no-restricted-syntax
21652180
await waitForTimeout(10);
21662181

21672182
readonly = await page.$eval(getSelector("353R"), el => el.disabled);
@@ -2201,15 +2216,19 @@ describe("Interaction", () => {
22012216
await page.click(getSelector("55R"));
22022217
await page.type(getSelector("55R"), "Hello", { delay: 10 });
22032218
await page.click(getSelector("56R"));
2219+
// eslint-disable-next-line no-restricted-syntax
22042220
await waitForTimeout(10);
22052221

22062222
await page.click(getSelector("55R"));
22072223
await page.type(getSelector("55R"), " World", { delay: 10 });
2224+
// eslint-disable-next-line no-restricted-syntax
22082225
await waitForTimeout(10);
22092226

22102227
await otherPages[i].bringToFront();
2228+
// eslint-disable-next-line no-restricted-syntax
22112229
await waitForTimeout(100);
22122230
await page.bringToFront();
2231+
// eslint-disable-next-line no-restricted-syntax
22132232
await waitForTimeout(100);
22142233

22152234
const text = await page.$eval(getSelector("55R"), el => el.value);
@@ -2245,6 +2264,7 @@ describe("Interaction", () => {
22452264
);
22462265

22472266
await page.click(getSelector("25R"));
2267+
// eslint-disable-next-line no-restricted-syntax
22482268
await waitForTimeout(10);
22492269
await page.click(getSelector("26R"));
22502270

test/integration/test_utils.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ async function clearInput(page, selector) {
115115
await page.click(selector);
116116
await kbSelectAll(page);
117117
await page.keyboard.press("Backspace");
118+
// eslint-disable-next-line no-restricted-syntax
118119
await waitForTimeout(10);
119120
}
120121

@@ -353,6 +354,7 @@ async function serializeBitmapDimensions(page) {
353354
async function dragAndDropAnnotation(page, startX, startY, tX, tY) {
354355
await page.mouse.move(startX, startY);
355356
await page.mouse.down();
357+
// eslint-disable-next-line no-restricted-syntax
356358
await waitForTimeout(10);
357359
await page.mouse.move(startX + tX, startY + tY);
358360
await page.mouse.up();

0 commit comments

Comments
 (0)