diff --git a/site/e2e/README.md b/site/e2e/README.md index 291344a67c..315de9dd47 100644 --- a/site/e2e/README.md +++ b/site/e2e/README.md @@ -46,3 +46,11 @@ Enterprise tests require a license key to run. ```shell export CODER_E2E_ENTERPRISE_LICENSE= ``` + +# Debugging tests + +To debug a test, it is more helpful to run it in `ui` mode. + +``` +pnpm playwright:test-ui +``` diff --git a/site/e2e/api.ts b/site/e2e/api.ts index 88f8666475..9bb8d62719 100644 --- a/site/e2e/api.ts +++ b/site/e2e/api.ts @@ -6,8 +6,12 @@ import { findSessionToken, randomName } from "./helpers"; let currentOrgId: string; export const setupApiCalls = async (page: Page) => { - const token = await findSessionToken(page); - API.setSessionToken(token); + try { + const token = await findSessionToken(page); + API.setSessionToken(token); + } catch { + // If this fails, we have an unauthenticated client. + } API.setHost(`http://127.0.0.1:${coderPort}`); }; diff --git a/site/e2e/global.setup.ts b/site/e2e/global.setup.ts index fd37b29ea5..b99c461308 100644 --- a/site/e2e/global.setup.ts +++ b/site/e2e/global.setup.ts @@ -1,10 +1,19 @@ import { expect, test } from "@playwright/test"; +import { hasFirstUser } from "api/api"; import { Language } from "pages/CreateUserPage/CreateUserForm"; +import { setupApiCalls } from "./api"; import * as constants from "./constants"; import { storageState } from "./playwright.config"; test("setup deployment", async ({ page }) => { await page.goto("/", { waitUntil: "domcontentloaded" }); + await setupApiCalls(page); + const exists = await hasFirstUser(); + // First user already exists, abort early. All tests execute this as a dependency, + // if you run multiple tests in the UI, this will fail unless we check this. + if (exists) { + return; + } // Setup first user await page.getByLabel(Language.usernameLabel).fill(constants.username); diff --git a/site/package.json b/site/package.json index 016f0bdafa..24ba4d5262 100644 --- a/site/package.json +++ b/site/package.json @@ -16,6 +16,7 @@ "lint:types": "tsc -p .", "playwright:install": "playwright install --with-deps chromium", "playwright:test": "playwright test --config=e2e/playwright.config.ts", + "playwright:test-ui": "playwright test --config=e2e/playwright.config.ts --ui $([[ \"$CODER\" == \"true\" ]] && echo --ui-port=7500 --ui-host=0.0.0.0)", "gen:provisioner": "protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./e2e/ --ts_proto_opt=outputJsonMethods=false,outputEncodeMethods=encode-no-creation,outputClientImpl=false,nestJs=false,outputPartialMethods=false,fileSuffix=Generated,suffix=hey -I ../provisionersdk/proto ../provisionersdk/proto/provisioner.proto && pnpm exec prettier --ignore-path '/dev/null' --cache --write './e2e/provisionerGenerated.ts'", "storybook": "STORYBOOK=true storybook dev -p 6006", "storybook:build": "storybook build",