Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93b46fe

Browse files
Emyrkaslilac
andauthored
chore: skip global.setup if first user already exists (coder#12930)
* chore: skip global.setup if first user already exists treat test as a setup, rather than a test Co-authored-by: Kayla Washburn-Love <[email protected]> --------- Co-authored-by: Kayla Washburn-Love <[email protected]>
1 parent 2ad7fcc commit 93b46fe

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

site/e2e/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ Enterprise tests require a license key to run.
4646
```shell
4747
export CODER_E2E_ENTERPRISE_LICENSE=<license key>
4848
```
49+
50+
# Debugging tests
51+
52+
To debug a test, it is more helpful to run it in `ui` mode.
53+
54+
```
55+
pnpm playwright:test-ui
56+
```

site/e2e/api.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { findSessionToken, randomName } from "./helpers";
66
let currentOrgId: string;
77

88
export const setupApiCalls = async (page: Page) => {
9-
const token = await findSessionToken(page);
10-
API.setSessionToken(token);
9+
try {
10+
const token = await findSessionToken(page);
11+
API.setSessionToken(token);
12+
} catch {
13+
// If this fails, we have an unauthenticated client.
14+
}
1115
API.setHost(`http://127.0.0.1:${coderPort}`);
1216
};
1317

site/e2e/global.setup.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { expect, test } from "@playwright/test";
2+
import { hasFirstUser } from "api/api";
23
import { Language } from "pages/CreateUserPage/CreateUserForm";
4+
import { setupApiCalls } from "./api";
35
import * as constants from "./constants";
46
import { storageState } from "./playwright.config";
57

68
test("setup deployment", async ({ page }) => {
79
await page.goto("/", { waitUntil: "domcontentloaded" });
10+
await setupApiCalls(page);
11+
const exists = await hasFirstUser();
12+
// First user already exists, abort early. All tests execute this as a dependency,
13+
// if you run multiple tests in the UI, this will fail unless we check this.
14+
if (exists) {
15+
return;
16+
}
817

918
// Setup first user
1019
await page.getByLabel(Language.usernameLabel).fill(constants.username);

site/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"lint:types": "tsc -p .",
1717
"playwright:install": "playwright install --with-deps chromium",
1818
"playwright:test": "playwright test --config=e2e/playwright.config.ts",
19+
"playwright:test-ui": "playwright test --config=e2e/playwright.config.ts --ui $([[ \"$CODER\" == \"true\" ]] && echo --ui-port=7500 --ui-host=0.0.0.0)",
1920
"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'",
2021
"storybook": "STORYBOOK=true storybook dev -p 6006",
2122
"storybook:build": "storybook build",

0 commit comments

Comments
 (0)