From 4ae1f40eeef029ae0b161f73f71e3e2b6cc91da0 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 19 Mar 2024 19:25:05 +0100 Subject: [PATCH] chore: add docs for adding e2e tests (#12677) --- site/e2e/README.md | 22 ++++++++++++++++++++++ site/e2e/global.setup.ts | 4 ++-- site/e2e/helpers.ts | 2 +- site/e2e/playwright.config.ts | 5 +++-- site/e2e/pom/BasePom.ts | 17 ----------------- site/e2e/pom/SignInPage.ts | 17 ----------------- site/e2e/pom/WorkspacesPage.ts | 8 -------- site/e2e/pom/index.ts | 2 -- site/e2e/states/.gitkeep | 0 9 files changed, 28 insertions(+), 49 deletions(-) create mode 100644 site/e2e/README.md delete mode 100644 site/e2e/pom/BasePom.ts delete mode 100644 site/e2e/pom/SignInPage.ts delete mode 100644 site/e2e/pom/WorkspacesPage.ts delete mode 100644 site/e2e/pom/index.ts delete mode 100644 site/e2e/states/.gitkeep diff --git a/site/e2e/README.md b/site/e2e/README.md new file mode 100644 index 0000000000..698d470e34 --- /dev/null +++ b/site/e2e/README.md @@ -0,0 +1,22 @@ +# e2e + +The structure of the end-to-end tests is optimized for speed and reliability. +Not all tests require setting up a new PostgreSQL instance or using the +Terraform provisioner. Deciding when to trade time for robustness rests with the +developers; the framework's role is to facilitate this process. + +Take a look at prior art in `tests/` for inspiration. To run a test: + +```shell +cd site +# Build the frontend assets. If you are actively changing +# the site to debug an issue, add `--watch`. +pnpm build +# Install the browsers to `~/.cache/ms-playwright`. +pnpm playwright:install +# Run E2E tests. You can see the configuration of the server +# in `playwright.config.ts`. This uses `go run -tags embed ...`. +pnpm playwright:test +# Run a specific test (`-g` stands for grep. It accepts regex). +pnpm playwright:test -g '' +``` diff --git a/site/e2e/global.setup.ts b/site/e2e/global.setup.ts index 11dc99923a..9336791f35 100644 --- a/site/e2e/global.setup.ts +++ b/site/e2e/global.setup.ts @@ -1,7 +1,7 @@ import { test, expect } from "@playwright/test"; import { Language } from "pages/CreateUserPage/CreateUserForm"; import * as constants from "./constants"; -import { STORAGE_STATE } from "./playwright.config"; +import { storageState } from "./playwright.config"; test("setup first user", async ({ page }) => { await page.goto("/", { waitUntil: "domcontentloaded" }); @@ -12,7 +12,7 @@ test("setup first user", async ({ page }) => { await page.getByTestId("create").click(); await expect(page).toHaveURL(/\/workspaces.*/); - await page.context().storageState({ path: STORAGE_STATE }); + await page.context().storageState({ path: storageState }); await page.getByTestId("button-select-template").isVisible(); }); diff --git a/site/e2e/helpers.ts b/site/e2e/helpers.ts index d42ab90fb5..6037f9f1ab 100644 --- a/site/e2e/helpers.ts +++ b/site/e2e/helpers.ts @@ -727,7 +727,7 @@ export const updateTemplateSettings = async ( templateName: string, templateSettingValues: Pick< UpdateTemplateMeta, - "name" | "display_name" | "description" + "name" | "display_name" | "description" | "deprecation_message" >, ) => { await page.goto(`/templates/${templateName}/settings`, { diff --git a/site/e2e/playwright.config.ts b/site/e2e/playwright.config.ts index dd70350e7f..95e671485e 100644 --- a/site/e2e/playwright.config.ts +++ b/site/e2e/playwright.config.ts @@ -10,7 +10,8 @@ export const wsEndpoint = process.env.CODER_E2E_WS_ENDPOINT; const coderMain = path.join(__dirname, "../../enterprise/cmd/coder"); -export const STORAGE_STATE = path.join(__dirname, ".auth.json"); +// This is where auth cookies are stored! +export const storageState = path.join(__dirname, ".auth.json"); const localURL = (port: number, path: string): string => { return `http://localhost:${port}${path}`; @@ -27,7 +28,7 @@ export default defineConfig({ testMatch: /.*\.spec\.ts/, dependencies: ["setup"], use: { - storageState: STORAGE_STATE, + storageState: storageState, }, timeout: 60_000, }, diff --git a/site/e2e/pom/BasePom.ts b/site/e2e/pom/BasePom.ts deleted file mode 100644 index 8c371637a8..0000000000 --- a/site/e2e/pom/BasePom.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Page } from "@playwright/test"; - -export abstract class BasePom { - protected readonly baseURL: string | undefined; - protected readonly path: string; - protected readonly page: Page; - - constructor(baseURL: string | undefined, path: string, page: Page) { - this.baseURL = baseURL; - this.path = path; - this.page = page; - } - - get url(): string { - return this.baseURL + this.path; - } -} diff --git a/site/e2e/pom/SignInPage.ts b/site/e2e/pom/SignInPage.ts deleted file mode 100644 index 365a3b941b..0000000000 --- a/site/e2e/pom/SignInPage.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Page } from "@playwright/test"; -import { BasePom } from "./BasePom"; - -export class SignInPage extends BasePom { - constructor(baseURL: string | undefined, page: Page) { - super(baseURL, "/login", page); - } - - async submitBuiltInAuthentication( - email: string, - password: string, - ): Promise { - await this.page.fill("text=Email", email); - await this.page.fill("text=Password", password); - await this.page.click('button:has-text("Sign In")'); - } -} diff --git a/site/e2e/pom/WorkspacesPage.ts b/site/e2e/pom/WorkspacesPage.ts deleted file mode 100644 index 1a1fbc0cfe..0000000000 --- a/site/e2e/pom/WorkspacesPage.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { Page } from "@playwright/test"; -import { BasePom } from "./BasePom"; - -export class WorkspacesPage extends BasePom { - constructor(baseURL: string | undefined, page: Page, params?: string) { - super(baseURL, `/workspaces${params && params}`, page); - } -} diff --git a/site/e2e/pom/index.ts b/site/e2e/pom/index.ts deleted file mode 100644 index 3fbca5e88f..0000000000 --- a/site/e2e/pom/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./SignInPage"; -export * from "./WorkspacesPage"; diff --git a/site/e2e/states/.gitkeep b/site/e2e/states/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000