Skip to content

chore: skip global.setup if first user already exists #12930

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

Merged
merged 7 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions site/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ Enterprise tests require a license key to run.
```shell
export CODER_E2E_ENTERPRISE_LICENSE=<license key>
```

# Debugging tests

To debug a test, it is more helpful to run it in `ui` mode.

```
pnpm playwright:test-ui
```
8 changes: 6 additions & 2 deletions site/e2e/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};

Expand Down
9 changes: 9 additions & 0 deletions site/e2e/global.setup.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading