mirror of https://github.com/coder/coder.git
chore: add docs for adding e2e tests (#12677)
This commit is contained in:
parent
c92ceffac9
commit
4ae1f40eee
|
@ -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 '<your test here>'
|
||||
```
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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`, {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<void> {
|
||||
await this.page.fill("text=Email", email);
|
||||
await this.page.fill("text=Password", password);
|
||||
await this.page.click('button:has-text("Sign In")');
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
export * from "./SignInPage";
|
||||
export * from "./WorkspacesPage";
|
Loading…
Reference in New Issue