Skip to content

Commit a78f318

Browse files
authored
test: update @playwright/test to 1.59.1 and fix e2e tests (#381)
1 parent a335782 commit a78f318

4 files changed

Lines changed: 564 additions & 54 deletions

File tree

e2e-tests/code-editing-and-ast-interaction.test.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,9 @@ test(`should change code, then highlight code and AST nodes matching ESQuery sel
3939
}) => {
4040
await page.goto("/");
4141

42-
// focus code editor textbox
4342
await page
44-
.getByRole("region", { name: "Code Editor Panel" })
45-
.getByRole("textbox")
46-
.nth(1)
47-
.click();
48-
49-
// delete the default code
50-
await page.keyboard.press("ControlOrMeta+KeyA");
51-
await page.keyboard.press("Backspace");
52-
53-
// add new code
54-
await page.keyboard.type("console.log('Hello, World!');");
43+
.getByRole("textbox", { name: "Code Editor", exact: true })
44+
.fill("console.log('Hello, World!');");
5545

5646
// add an ESQuery selector
5747
await page.getByRole("textbox", { name: "ESQuery Selector" }).click();
@@ -86,22 +76,19 @@ test(`should keep ESQuery highlights aligned while typing before a matching lite
8676
}) => {
8777
await page.goto("/");
8878

89-
const codeEditor = page
90-
.getByRole("region", { name: "Code Editor Panel" })
91-
.getByRole("textbox")
92-
.nth(1);
93-
const highlight = page.locator(".bg-editorHighlightedRangeColor");
79+
const codeEditor = page.getByRole("textbox", {
80+
name: "Code Editor",
81+
exact: true,
82+
});
83+
const highlight = codeEditor.locator(".bg-editorHighlightedRangeColor");
9484

95-
await codeEditor.click();
96-
await codeEditor.press("ControlOrMeta+KeyA");
97-
await codeEditor.press("Backspace");
98-
await codeEditor.pressSequentially("42;");
85+
await codeEditor.fill("42;");
9986

10087
await page
10188
.getByRole("textbox", { name: "ESQuery Selector" })
10289
.fill("Literal");
10390

104-
await expect(highlight).toHaveText("42");
91+
await expect(highlight).toHaveText(["42"]);
10592

10693
await codeEditor.click();
10794
await codeEditor.press("Home");
@@ -138,5 +125,5 @@ test(`should keep ESQuery highlights aligned while typing before a matching lite
138125
expect(
139126
highlightSamples.every(highlightText => highlightText === "42"),
140127
).toBe(true);
141-
await expect(highlight).toHaveText("42");
128+
await expect(highlight).toHaveText(["42"]);
142129
});

e2e-tests/persistence.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,6 @@ async function getStoredHashValue(page: Page): Promise<string> {
4747
}, storageKey);
4848
}
4949

50-
async function replaceEditorValue(page: Page, value: string) {
51-
const codeEditor = page
52-
.getByRole("region", { name: "Code Editor Panel" })
53-
.getByRole("textbox")
54-
.nth(1);
55-
56-
await codeEditor.click();
57-
await codeEditor.press("ControlOrMeta+KeyA");
58-
await codeEditor.press("Backspace");
59-
await codeEditor.pressSequentially(value);
60-
}
61-
6250
//-----------------------------------------------------------------------------
6351
// Tests
6452
//-----------------------------------------------------------------------------
@@ -70,8 +58,12 @@ test("should persist unicode code safely in the URL hash", async ({ page }) => {
7058
await page.goto("/");
7159

7260
const unicodeCode = 'const \u03C0 = "\u{1F600}";';
61+
const codeEditor = page.getByRole("textbox", {
62+
name: "Code Editor",
63+
exact: true,
64+
});
7365

74-
await replaceEditorValue(page, unicodeCode);
66+
await codeEditor.fill(unicodeCode);
7567

7668
await expect.poll(() => getPersistedJavaScriptCode(page)).toBe(unicodeCode);
7769
await expect.poll(() => getStoredHashValue(page)).toContain("v2.");
@@ -83,7 +75,7 @@ test("should persist unicode code safely in the URL hash", async ({ page }) => {
8375
}, storageKey);
8476
await page.goto(`/${persistedHash}`);
8577

86-
await expect(page.locator(".cm-content")).toContainText(unicodeCode);
78+
await expect(codeEditor).toContainText(unicodeCode);
8779
});
8880

8981
test("should still load state from legacy hash links", async ({ page }) => {
@@ -93,8 +85,12 @@ test("should still load state from legacy hash links", async ({ page }) => {
9385
await page.goto("/");
9486

9587
const legacyCode = "console.log('legacy hash');";
88+
const codeEditor = page.getByRole("textbox", {
89+
name: "Code Editor",
90+
exact: true,
91+
});
9692

97-
await replaceEditorValue(page, legacyCode);
93+
await codeEditor.fill(legacyCode);
9894

9995
await expect.poll(() => getPersistedJavaScriptCode(page)).toBe(legacyCode);
10096

@@ -114,7 +110,7 @@ test("should still load state from legacy hash links", async ({ page }) => {
114110
}, storageKey);
115111
await page.goto(`/#${legacyHash}`);
116112

117-
await expect(page.locator(".cm-content")).toContainText(legacyCode);
113+
await expect(codeEditor).toContainText(legacyCode);
118114
});
119115

120116
test("should fall back to localStorage when a v2 hash is malformed", async ({
@@ -126,8 +122,12 @@ test("should fall back to localStorage when a v2 hash is malformed", async ({
126122
await page.goto("/");
127123

128124
const fallbackCode = "console.log('localStorage fallback');";
125+
const codeEditor = page.getByRole("textbox", {
126+
name: "Code Editor",
127+
exact: true,
128+
});
129129

130-
await replaceEditorValue(page, fallbackCode);
130+
await codeEditor.fill(fallbackCode);
131131

132132
await expect
133133
.poll(() => getPersistedJavaScriptCode(page))
@@ -161,5 +161,5 @@ test("should fall back to localStorage when a v2 hash is malformed", async ({
161161
);
162162
await page.goto(`/#${malformedHash}`);
163163

164-
await expect(page.locator(".cm-content")).toContainText(fallbackCode);
164+
await expect(codeEditor).toContainText(fallbackCode);
165165
});

0 commit comments

Comments
 (0)