Skip to content

chore: add more e2e template settings tests #12717

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 10 commits into from
Mar 28, 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
10 changes: 9 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,19 @@ jobs:
- run: pnpm playwright:install
working-directory: site

- run: pnpm playwright:test --workers 1
# Run tests that don't require an enterprise license without an enterprise license
- run: pnpm playwright:test --forbid-only --workers 1
env:
DEBUG: pw:api
working-directory: site

# Run all of the tests with an enterprise license
- run: pnpm playwright:test --forbid-only --workers 1
env:
DEBUG: pw:api
CODER_E2E_ENTERPRISE_LICENSE: ${{ secrets.CODER_E2E_ENTERPRISE_LICENSE }}
working-directory: site

- name: Upload Playwright Failed Tests
if: always() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion scripts/remote_playwright.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -euo pipefail

workspace=${1:-}
coder_repo=${2:-.}
port=${3:-3000}
port=${3:-3111}

if [[ -z "${workspace}" ]]; then
echo "Usage: $0 <workspace> [workspace coder/coder dir] [e2e port]"
Expand Down
6 changes: 6 additions & 0 deletions site/e2e/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import * as path from "path";

export const coderMain = path.join(__dirname, "../../enterprise/cmd/coder");

// Default port from the server
export const coderPort = process.env.CODER_E2E_PORT
? Number(process.env.CODER_E2E_PORT)
Expand Down Expand Up @@ -28,3 +32,5 @@ export const gitAuth = {
validatePath: "/validate",
installationsPath: "/installations",
};

export const enterpriseLicense = process.env.CODER_E2E_ENTERPRISE_LICENSE ?? "";
12 changes: 12 additions & 0 deletions site/e2e/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { storageState } from "./playwright.config";
test("setup first user", async ({ page }) => {
await page.goto("/", { waitUntil: "domcontentloaded" });

// Setup first user
await page.getByLabel(Language.usernameLabel).fill(constants.username);
await page.getByLabel(Language.emailLabel).fill(constants.email);
await page.getByLabel(Language.passwordLabel).fill(constants.password);
Expand All @@ -15,4 +16,15 @@ test("setup first user", async ({ page }) => {
await page.context().storageState({ path: storageState });

await page.getByTestId("button-select-template").isVisible();

// Setup license
if (constants.enterpriseLicense) {
await page.goto("/deployment/licenses", { waitUntil: "domcontentloaded" });

await page.getByText("Add a license").click();
await page.getByRole("textbox").fill(constants.enterpriseLicense);
await page.getByText("Upload License").click();

await page.getByText("You have successfully added a license").isVisible();
}
});
33 changes: 16 additions & 17 deletions site/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type BrowserContext, expect, type Page } from "@playwright/test";
import { type BrowserContext, expect, type Page, test } from "@playwright/test";
import axios from "axios";
import { type ChildProcess, exec, spawn } from "child_process";
import { randomUUID } from "crypto";
Expand All @@ -12,7 +12,13 @@ import type {
UpdateTemplateMeta,
} from "api/typesGenerated";
import { TarWriter } from "utils/tar";
import { agentPProfPort, coderPort, prometheusPort } from "./constants";
import {
agentPProfPort,
coderMain,
coderPort,
enterpriseLicense,
prometheusPort,
} from "./constants";
import {
Agent,
type App,
Expand All @@ -25,6 +31,11 @@ import {
type RichParameter,
} from "./provisionerGenerated";

// requiresEnterpriseLicense will skip the test if we're not running with an enterprise license
export function requiresEnterpriseLicense() {
test.skip(!enterpriseLicense);
}

// createWorkspace creates a workspace for a template.
// It does not wait for it to be running, but it does navigate to the page.
export const createWorkspace = async (
Expand Down Expand Up @@ -147,7 +158,7 @@ export const sshIntoWorkspace = async (
binaryArgs: string[] = [],
): Promise<ssh.Client> => {
if (binaryPath === "go") {
binaryArgs = ["run", coderMainPath()];
binaryArgs = ["run", coderMain];
}
const sessionToken = await findSessionToken(page);
return new Promise<ssh.Client>((resolve, reject) => {
Expand Down Expand Up @@ -229,7 +240,7 @@ export const startAgent = async (
page: Page,
token: string,
): Promise<ChildProcess> => {
return startAgentWithCommand(page, token, "go", "run", coderMainPath());
return startAgentWithCommand(page, token, "go", "run", coderMain);
};

// downloadCoderVersion downloads the version provided into a temporary dir and
Expand Down Expand Up @@ -358,18 +369,6 @@ const waitUntilUrlIsNotResponding = async (url: string) => {
);
};

const coderMainPath = (): string => {
return path.join(
__dirname,
"..",
"..",
"enterprise",
"cmd",
"coder",
"main.go",
);
};

// Allows users to more easily define properties they want for agents and resources!
type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
Expand Down Expand Up @@ -686,7 +685,7 @@ export const updateTemplate = async (
"go",
[
"run",
coderMainPath(),
coderMain,
"templates",
"push",
"--test.provisioner",
Expand Down
14 changes: 5 additions & 9 deletions site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { defineConfig } from "@playwright/test";
import path from "path";
import { coderPort, coderdPProfPort, gitAuth } from "./constants";
import * as path from "path";
import { coderMain, coderPort, coderdPProfPort, gitAuth } from "./constants";

export const wsEndpoint = process.env.CODER_E2E_WS_ENDPOINT;

const coderMain = path.join(__dirname, "../../enterprise/cmd/coder");

// This is where auth cookies are stored!
export const storageState = path.join(__dirname, ".auth.json");

Expand All @@ -16,16 +14,14 @@ const localURL = (port: number, path: string): string => {
export default defineConfig({
projects: [
{
name: "setup",
name: "testsSetup",
testMatch: /global.setup\.ts/,
},
{
name: "tests",
testMatch: /.*\.spec\.ts/,
dependencies: ["setup"],
use: {
storageState: storageState,
},
dependencies: ["testsSetup"],
use: { storageState },
timeout: 60_000,
},
],
Expand Down
29 changes: 27 additions & 2 deletions site/e2e/tests/updateTemplate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { test } from "@playwright/test";
import { createTemplate, updateTemplateSettings } from "../helpers";
import { expect, test } from "@playwright/test";
import {
createTemplate,
requiresEnterpriseLicense,
updateTemplateSettings,
} from "../helpers";

test("template update with new name redirects on successful submit", async ({
page,
Expand All @@ -10,3 +14,24 @@ test("template update with new name redirects on successful submit", async ({
name: "new-name",
});
});

test("require latest version", async ({ page }) => {
requiresEnterpriseLicense();

const templateName = await createTemplate(page);

await page.goto(`/templates/${templateName}/settings`, {
waitUntil: "domcontentloaded",
});
await expect(page).toHaveURL(`/templates/${templateName}/settings`);
let checkbox = await page.waitForSelector("#require_active_version");
await checkbox.click();
await page.getByTestId("form-submit").click();

await page.goto(`/templates/${templateName}/settings`, {
waitUntil: "domcontentloaded",
});
checkbox = await page.waitForSelector("#require_active_version");
await checkbox.scrollIntoViewIfNeeded();
expect(await checkbox.isChecked()).toBe(true);
});
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
},
"devDependencies": {
"@octokit/types": "12.3.0",
"@playwright/test": "1.39.0",
"@playwright/test": "1.42.1",
"@storybook/addon-actions": "7.6.11",
"@storybook/addon-essentials": "7.6.11",
"@storybook/addon-interactions": "7.6.11",
Expand Down
20 changes: 10 additions & 10 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading