Skip to content

Commit 6bebeac

Browse files
authored
chore: upgrade playwright, use page.consoleMessages() (#2938)
1 parent e43753f commit 6bebeac

File tree

5 files changed

+29
-41
lines changed

5 files changed

+29
-41
lines changed

package-lock.json

Lines changed: 17 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
8484
"@mswjs/http-middleware": "^0.10.3",
8585
"@oxide/openapi-gen-ts": "~0.9.0",
86-
"@playwright/test": "^1.54.1",
86+
"@playwright/test": "^1.56.1",
8787
"@testing-library/dom": "^10.4.0",
8888
"@testing-library/jest-dom": "^6.6.3",
8989
"@testing-library/react": "^16.2.0",
@@ -104,7 +104,7 @@
104104
"eslint-config-prettier": "^9.1.0",
105105
"eslint-plugin-import": "^2.31.0",
106106
"eslint-plugin-jsx-a11y": "^6.10.2",
107-
"eslint-plugin-playwright": "^1.8.3",
107+
"eslint-plugin-playwright": "^2.2.2",
108108
"eslint-plugin-prettier": "^5.2.1",
109109
"eslint-plugin-react": "^7.37.3",
110110
"eslint-plugin-react-hook-form": "^0.3.0",

test/e2e/error-pages.e2e.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
import { expect, test } from '@playwright/test'
99

10-
import { getPageAsUser } from './utils'
10+
import { getPageAsUser, hasConsoleMessage } from './utils'
1111

1212
test('Shows 404 page when a resource is not found', async ({ page }) => {
1313
await page.goto('/nonexistent')
@@ -20,9 +20,6 @@ test('Shows 404 page when a resource is not found', async ({ page }) => {
2020
})
2121

2222
test('Shows something went wrong page on other errors', async ({ page, browserName }) => {
23-
const messages: string[] = []
24-
page.on('console', (e) => messages.push(e.text()))
25-
2623
await page.goto('/projects/error-503') // specially handled in mock server
2724
await expect(page.getByText('Something went wrong')).toBeVisible()
2825

@@ -36,7 +33,7 @@ test('Shows something went wrong page on other errors', async ({ page, browserNa
3633
const error =
3734
'Expected query to be prefetched.\nKey: ["projectView",{"path":{"project":"error-503"}}]'
3835
// eslint-disable-next-line playwright/no-conditional-expect
39-
expect(messages.some((m) => m.includes(error))).toBeTruthy()
36+
expect(await hasConsoleMessage(page, error)).toBeTruthy()
4037
}
4138

4239
// test clicking sign out

test/e2e/instance-metrics.e2e.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { expect, test } from '@playwright/test'
1010

1111
import { OXQL_GROUP_BY_ERROR } from '~/api'
1212

13-
import { getPageAsUser } from './utils'
13+
import { getPageAsUser, hasConsoleMessage } from './utils'
1414

1515
test('Click through instance metrics', async ({ page }) => {
1616
await page.goto('/projects/mock-project/instances/db1/metrics/cpu')
@@ -45,9 +45,6 @@ test('Instance metrics work for non-fleet viewer', async ({ browser }) => {
4545
})
4646

4747
test('empty and loading states', async ({ page }) => {
48-
const messages: string[] = []
49-
page.on('console', (e) => messages.push(e.text()))
50-
5148
// we have special handling in the API to return special data for this project
5249
await page.goto('/projects/other-project/instances/failed-restarting-soon/metrics/cpu')
5350

@@ -70,16 +67,14 @@ test('empty and loading states', async ({ page }) => {
7067
await expect(noData).toBeVisible()
7168

7269
// idle state returns group_by must be aligned error, treated as empty
73-
const hasGroupByError = () => messages.some((m) => m.includes(OXQL_GROUP_BY_ERROR))
74-
75-
expect(hasGroupByError()).toBe(false) // error not in console
70+
expect(await hasConsoleMessage(page, OXQL_GROUP_BY_ERROR)).toBe(false) // error not in console
7671
await statePicker.click()
7772
await page.getByRole('option', { name: 'State: Idle' }).click()
7873
await expect(loading).toBeVisible()
7974
await expect(loading).toBeHidden()
8075
await expect(page.getByText('Something went wrong')).toBeHidden()
8176
await expect(noData).toBeVisible()
82-
expect(hasGroupByError()).toBe(true) // error present in console
77+
expect(await hasConsoleMessage(page, OXQL_GROUP_BY_ERROR)).toBe(true) // error present in console
8378

8479
// make sure empty state goes away again for the first one
8580
await statePicker.click()

test/e2e/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,8 @@ export async function addTlsCert(page: Page) {
263263
await chooseFile(page, page.getByLabel('Key'), 'small')
264264
await page.getByRole('button', { name: 'Add Certificate' }).click()
265265
}
266+
267+
export async function hasConsoleMessage(page: Page, msg: string) {
268+
const messages = await page.consoleMessages()
269+
return messages.some((m) => m.text().includes(msg))
270+
}

0 commit comments

Comments
 (0)