From e6021d5c63f0ebda6d501cf3ce8364041d7dc23d Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 10 Apr 2024 14:12:09 -0500 Subject: [PATCH 1/7] chore: skip global.setup if first user already exists treat test as a setup, rather than a test --- site/e2e/global.setup.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/site/e2e/global.setup.ts b/site/e2e/global.setup.ts index b4f92c423bdab..73b015b882964 100644 --- a/site/e2e/global.setup.ts +++ b/site/e2e/global.setup.ts @@ -1,9 +1,17 @@ import { expect, test } from "@playwright/test"; +import { hasFirstUser } from "api/api"; import { Language } from "pages/CreateUserPage/CreateUserForm"; import * as constants from "./constants"; import { storageState } from "./playwright.config"; test("setup deployment", async ({ page }) => { + const exists = await hasFirstUser(); + if (exists) { + // 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. + return; + } + await page.goto("/", { waitUntil: "domcontentloaded" }); // Setup first user From 1b721ed4cecbae25b6eb2d32f68587c553267bb1 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 10 Apr 2024 14:19:50 -0500 Subject: [PATCH 2/7] fixup api route url --- site/e2e/api.ts | 8 +++++--- site/e2e/global.setup.ts | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/site/e2e/api.ts b/site/e2e/api.ts index 88f8666475507..f8205556d7781 100644 --- a/site/e2e/api.ts +++ b/site/e2e/api.ts @@ -5,9 +5,11 @@ import { findSessionToken, randomName } from "./helpers"; let currentOrgId: string; -export const setupApiCalls = async (page: Page) => { - const token = await findSessionToken(page); - API.setSessionToken(token); +export const setupApiCalls = async (page: Page, unauthenticated?: boolean) => { + if (!unauthenticated) { + const token = await findSessionToken(page); + API.setSessionToken(token); + } API.setHost(`http://127.0.0.1:${coderPort}`); }; diff --git a/site/e2e/global.setup.ts b/site/e2e/global.setup.ts index 73b015b882964..c22c74e464ba1 100644 --- a/site/e2e/global.setup.ts +++ b/site/e2e/global.setup.ts @@ -1,10 +1,13 @@ 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, true); const exists = await hasFirstUser(); if (exists) { // First user already exists, abort early. All tests execute this as a dependency, @@ -12,8 +15,6 @@ test("setup deployment", async ({ page }) => { return; } - await page.goto("/", { waitUntil: "domcontentloaded" }); - // Setup first user await page.getByLabel(Language.usernameLabel).fill(constants.username); await page.getByLabel(Language.emailLabel).fill(constants.email); From 7c382ab61dd320a5c6e6420de51b37a07df50124 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 10 Apr 2024 14:55:51 -0500 Subject: [PATCH 3/7] add ui mode --- site/e2e/README.md | 8 ++++++++ site/package.json | 2 ++ 2 files changed, 10 insertions(+) diff --git a/site/e2e/README.md b/site/e2e/README.md index 291344a67c61f..315de9dd476c7 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/package.json b/site/package.json index 016f0bdafa846..d350642df9798 100644 --- a/site/package.json +++ b/site/package.json @@ -16,6 +16,8 @@ "lint:types": "tsc -p .", "playwright:install": "playwright install --with-deps chromium", "playwright:test": "playwright test --config=e2e/playwright.config.ts", + "//": "If we are in a coder workspace, use the `ui-port` to allow opening remotely. If native, use the default app. It's generally a bit smoother to use.", + "playwright:test-ui": "playwright test --config=e2e/playwright.config.ts --ui `[[ \"$CODER\" == \"true\" ]] && --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", From b9bc1a189e57d5e69b0ab6aa3187ed956699403f Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 10 Apr 2024 15:01:38 -0500 Subject: [PATCH 4/7] Fix package.json --- site/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/package.json b/site/package.json index d350642df9798..1111a7f53e521 100644 --- a/site/package.json +++ b/site/package.json @@ -17,7 +17,7 @@ "playwright:install": "playwright install --with-deps chromium", "playwright:test": "playwright test --config=e2e/playwright.config.ts", "//": "If we are in a coder workspace, use the `ui-port` to allow opening remotely. If native, use the default app. It's generally a bit smoother to use.", - "playwright:test-ui": "playwright test --config=e2e/playwright.config.ts --ui `[[ \"$CODER\" == \"true\" ]] && --ui-port=7500 --ui-host=0.0.0.0`", + "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", From fb29ca4b4f49949012303354727aac981f1c6d36 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 11 Apr 2024 08:18:56 -0500 Subject: [PATCH 5/7] remove boolean condition from setupAPICalls --- site/e2e/api.ts | 6 ++++-- site/e2e/global.setup.ts | 2 +- site/package.json | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/site/e2e/api.ts b/site/e2e/api.ts index f8205556d7781..88d6aa3162947 100644 --- a/site/e2e/api.ts +++ b/site/e2e/api.ts @@ -5,10 +5,12 @@ import { findSessionToken, randomName } from "./helpers"; let currentOrgId: string; -export const setupApiCalls = async (page: Page, unauthenticated?: boolean) => { - if (!unauthenticated) { +export const setupApiCalls = async (page: Page) => { + 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 c22c74e464ba1..0e65070a44d56 100644 --- a/site/e2e/global.setup.ts +++ b/site/e2e/global.setup.ts @@ -7,7 +7,7 @@ import { storageState } from "./playwright.config"; test("setup deployment", async ({ page }) => { await page.goto("/", { waitUntil: "domcontentloaded" }); - await setupApiCalls(page, true); + await setupApiCalls(page); const exists = await hasFirstUser(); if (exists) { // First user already exists, abort early. All tests execute this as a dependency, diff --git a/site/package.json b/site/package.json index 1111a7f53e521..24ba4d5262902 100644 --- a/site/package.json +++ b/site/package.json @@ -16,7 +16,6 @@ "lint:types": "tsc -p .", "playwright:install": "playwright install --with-deps chromium", "playwright:test": "playwright test --config=e2e/playwright.config.ts", - "//": "If we are in a coder workspace, use the `ui-port` to allow opening remotely. If native, use the default app. It's generally a bit smoother to use.", "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", From 8f2fbc1983386aa638ebfe1901079c66e0af4d0c Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 11 Apr 2024 09:12:01 -0500 Subject: [PATCH 6/7] make fmt --- site/e2e/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/e2e/api.ts b/site/e2e/api.ts index 88d6aa3162947..9bb8d62719066 100644 --- a/site/e2e/api.ts +++ b/site/e2e/api.ts @@ -6,7 +6,7 @@ import { findSessionToken, randomName } from "./helpers"; let currentOrgId: string; export const setupApiCalls = async (page: Page) => { - try{ + try { const token = await findSessionToken(page); API.setSessionToken(token); } catch { From 0d9e3351ff329cefc2412308bc8e88bb86be80e4 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 11 Apr 2024 16:05:07 -0500 Subject: [PATCH 7/7] Update site/e2e/global.setup.ts Co-authored-by: Kayla Washburn-Love --- site/e2e/global.setup.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/e2e/global.setup.ts b/site/e2e/global.setup.ts index 0e65070a44d56..73dde6595d540 100644 --- a/site/e2e/global.setup.ts +++ b/site/e2e/global.setup.ts @@ -9,9 +9,9 @@ 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) { - // 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. return; }