Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Playwright to use a custom test fixture with global mocks #2196

Merged
merged 19 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ module.exports = {
message:
"Do not use @vue/test-utils' `shallowMount`. Use `~~/test/unit/test-utils/render` instead which includes helpful context setup or @testing-library/vue's `render` directly.",
},
{
selector:
"ImportDeclaration[source.value='@playwright/test']:has(ImportSpecifier[local.name='test'])",
message:
"Do not import 'test' from '@playwright/test'. Use 'import { test } from '~~/test/playwright/utils/test-fixture' instead.",
zackkrida marked this conversation as resolved.
Show resolved Hide resolved
},
],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from "@playwright/test"
import { test } from "~~/test/playwright/utils/test-fixture"

import breakpoints from "~~/test/playwright/utils/breakpoints"

Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/all-results-keyboard.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import audio from "~~/test/playwright/utils/audio"

Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/attribution.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { turnOnAnalytics } from "~~/test/playwright/utils/navigation"

Expand Down
8 changes: 2 additions & 6 deletions frontend/test/playwright/e2e/audio-detail.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { mockProviderApis } from "~~/test/playwright/utils/route"
import { test } from "~~/test/playwright/utils/test-fixture"

const goToCustomAudioPage = async (page: Page) => {
// Test in a custom audio detail page, it should apply the same for any audio.
Expand All @@ -15,10 +15,6 @@ const showsErrorPage = async (page: Page) => {

test.describe.configure({ mode: "parallel" })

test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

test("shows the data that is only available in single result, not search response", async ({
page,
}) => {
Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/external-sources.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { goToSearchTerm, setCookies } from "~~/test/playwright/utils/navigation"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
LanguageDirection,
Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/filters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
assertCheckboxStatus,
Expand All @@ -8,8 +10,6 @@ import {
filters,
} from "~~/test/playwright/utils/navigation"

import { mockProviderApis } from "~~/test/playwright/utils/route"

import breakpoints from "~~/test/playwright/utils/breakpoints"

import {
Expand Down Expand Up @@ -42,9 +42,6 @@ const FILTER_COUNTS = {
}

breakpoints.describeMobileAndDesktop(() => {
test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})
for (const searchType of supportedSearchTypes) {
test(`correct total number of filters is displayed for ${searchType}`, async ({
page,
Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/global-audio.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect, test } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { sleep, t } from "~~/test/playwright/utils/navigation"
import breakpoints from "~~/test/playwright/utils/breakpoints"
Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/header-internal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
isDialogOpen,
Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/homepage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { expect, Page, test } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { mockProviderApis } from "~~/test/playwright/utils/route"
import { goToSearchTerm, t } from "~~/test/playwright/utils/navigation"

import { searchPath, supportedSearchTypes } from "~/constants/media"

test.describe.configure({ mode: "parallel" })

test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

for (const searchType of supportedSearchTypes) {
test(`can change type and search for ${searchType} from homepage`, async ({
page,
Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/image-detail.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { mockProviderApis } from "~~/test/playwright/utils/route"
import { t } from "~~/test/playwright/utils/navigation"

const goToCustomImagePage = async (page: Page) => {
Expand All @@ -16,10 +17,6 @@ const showsErrorPage = async (page: Page) => {

test.describe.configure({ mode: "parallel" })

test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

test("shows the author and title of the image", async ({ page }) => {
await goToCustomImagePage(page)
const author = page.locator('a[aria-label^="author"]')
Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/load-more.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { expect, Page, test } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
goToSearchTerm,
renderModes,
t,
} from "~~/test/playwright/utils/navigation"
import { mockProviderApis } from "~~/test/playwright/utils/route"

import { AUDIO, IMAGE, SupportedMediaType } from "~/constants/media"

Expand Down Expand Up @@ -39,10 +40,6 @@ const openSingleMediaView = async (
*/

test.describe("Load more button", () => {
test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

test("Clicking sends 2 requests on All view with enough results", async ({
page,
}) => {
Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/migration-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { t } from "~~/test/playwright/utils/navigation"

Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/mobile-menu.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
goToSearchTerm,
Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/recent-searches.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect, test, type Page } from "@playwright/test"
import { expect, type Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { searchFromHeader } from "~~/test/playwright/utils/navigation"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* redirect to the homepage.
*/

import { test, expect } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { searchTypes, searchPath } from "~/constants/media"

Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/report-media.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect, Page, BrowserContext } from "@playwright/test"
import { expect, Page, BrowserContext } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { mockProviderApis } from "~~/test/playwright/utils/route"
import {
goToSearchTerm,
openFirstResult,
Expand Down Expand Up @@ -80,10 +81,6 @@ const submitOtherReport = async (page: Page, context: BrowserContext) => {
return expect(response.status()).toBe(200)
}

test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

const reports = {
dmca: submitDmcaReport,
mature: submitMatureContentReport,
Expand Down
10 changes: 4 additions & 6 deletions frontend/test/playwright/e2e/search-navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect, Page, test } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
goToSearchTerm,
Expand All @@ -7,7 +9,7 @@ import {
openFirstResult,
t,
} from "~~/test/playwright/utils/navigation"
import { mockProviderApis } from "~~/test/playwright/utils/route"

import breakpoints from "~~/test/playwright/utils/breakpoints"

import { AUDIO, IMAGE, SupportedMediaType } from "~/constants/media"
Expand All @@ -21,10 +23,6 @@ const getContentLink = async (page: Page, mediaType: SupportedMediaType) => {

test.describe("search history navigation", () => {
breakpoints.describeMobileAndDesktop(() => {
test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

test("should update search results when back navigation changes filters", async ({
page,
}) => {
Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/search-query-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { expect, test } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
changeSearchType,
goToSearchTerm,
searchFromHeader,
} from "~~/test/playwright/utils/navigation"
import { mockProviderApis } from "~~/test/playwright/utils/route"

import breakpoints from "~~/test/playwright/utils/breakpoints"

Expand All @@ -27,10 +28,6 @@ test.describe.configure({ mode: "parallel" })

test.describe("search query on CSR", () => {
breakpoints.describeMobileAndDesktop(() => {
test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

test("q query parameter is set as the search term", async ({ page }) => {
await goToSearchTerm(page, "cat", { mode: "CSR" })

Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/search-query-server.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
assertCheckboxStatus,
Expand All @@ -7,7 +9,6 @@ import {
goToSearchTerm,
searchTypeNames,
} from "~~/test/playwright/utils/navigation"
import { mockProviderApis } from "~~/test/playwright/utils/route"

import breakpoints from "~~/test/playwright/utils/breakpoints"

Expand All @@ -29,10 +30,6 @@ test.describe.configure({ mode: "parallel" })

test.describe("search query on SSR", () => {
breakpoints.describeMobileAndDesktop(() => {
test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

test("q query parameter is set as the search term", async ({ page }) => {
await goToSearchTerm(page, "cat", {
query: "license=cc0&license_type=commercial&searchBy=creator",
Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/search-types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect, Page } from "@playwright/test"
import { expect, Page } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import {
changeSearchType,
goToSearchTerm,
} from "~~/test/playwright/utils/navigation"
import { mockProviderApis } from "~~/test/playwright/utils/route"
import breakpoints from "~~/test/playwright/utils/breakpoints"

import { searchPath } from "~/constants/media"
Expand Down Expand Up @@ -95,10 +96,6 @@ async function checkSearchResult(page: Page, searchType: SearchTypeConfig) {

test.describe("search types", () => {
breakpoints.describeMobileAndDesktop(() => {
test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

for (const searchType of searchTypes) {
test(`Can open ${searchType.name} search page on SSR`, async ({
page,
Expand Down
9 changes: 3 additions & 6 deletions frontend/test/playwright/e2e/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* When pending: does not show 'No images', Safer Browsing, search rating or error message
* On error: shows error message
*/
import { expect, test } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { mockProviderApis } from "~~/test/playwright/utils/route"
import {
goToSearchTerm,
scrollToBottom,
Expand All @@ -17,10 +18,6 @@ import {

test.describe.configure({ mode: "parallel" })

test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})

test("shows no results page when no results", async ({ page }) => {
await page.goto("/search/image?q=243f6a8885a308d3")
await expect(page.locator(".error-section")).toBeVisible()
Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/e2e/translation-banner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect } from "@playwright/test"
import { expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { dismissBannersUsingCookies } from "~~/test/playwright/utils/navigation"

Expand Down
2 changes: 1 addition & 1 deletion frontend/test/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const config: PlaywrightTestConfig = {
baseURL: "http://localhost:8443",
trace: "retain-on-failure",
},
timeout: 60 * 1e3,
timeout: 60 * 1e3, // 1 minute
/**
* When updating or recreating tapes, if we have more than one worker running
* then Talkback is liable to see multiple requests at the same time that would
Expand Down
4 changes: 3 additions & 1 deletion frontend/test/playwright/utils/breakpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { test, expect, Expect } from "@playwright/test"
import { expect, Expect } from "@playwright/test"

import { test } from "~~/test/playwright/utils/test-fixture"

import { VIEWPORTS } from "~/constants/screens"
import type { Breakpoint } from "~/constants/screens"
Expand Down
6 changes: 0 additions & 6 deletions frontend/test/playwright/utils/route.ts

This file was deleted.

Loading