From 237a5d1017cb3c000987348b1f8c3aeb7534bb5c Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Mon, 25 Mar 2024 21:43:25 +0000 Subject: [PATCH] fix: always use bash when executing web terminal tests --- site/e2e/helpers.ts | 24 ++++++++++++++++++++++-- site/e2e/tests/webTerminal.spec.ts | 10 +++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/site/e2e/helpers.ts b/site/e2e/helpers.ts index 6acfea9121c9c..7bf50b1c6d04f 100644 --- a/site/e2e/helpers.ts +++ b/site/e2e/helpers.ts @@ -1,4 +1,4 @@ -import { expect, type Page } from "@playwright/test"; +import { type BrowserContext, expect, type Page } from "@playwright/test"; import axios from "axios"; import { type ChildProcess, exec, spawn } from "child_process"; import { randomUUID } from "crypto"; @@ -445,7 +445,7 @@ const createTemplateVersionTar = async ( resource.agents = resource.agents?.map( (agent: RecursivePartial) => { if (agent.apps) { - agent.apps = agent.apps?.map((app: RecursivePartial) => { + agent.apps = agent.apps.map((app) => { return { command: "", displayName: "example", @@ -791,3 +791,23 @@ export const updateWorkspaceParameters = async ( state: "visible", }); }; + +export async function openTerminalWindow( + page: Page, + context: BrowserContext, + workspaceName: string, +): Promise { + // Wait for the web terminal to open in a new tab + const pagePromise = context.waitForEvent("page"); + await page.getByTestId("terminal").click(); + const terminal = await pagePromise; + await terminal.waitForLoadState("domcontentloaded"); + + // Specify that the shell should be `bash`, to prevent inheriting a shell that + // isn't POSIX compatible, such as Fish. + const commandQuery = `?command=${encodeURIComponent("/usr/bin/env bash")}`; + await expect(terminal).toHaveURL(`/@admin/${workspaceName}.dev/terminal`); + await terminal.goto(`/@admin/${workspaceName}.dev/terminal${commandQuery}`); + + return terminal; +} diff --git a/site/e2e/tests/webTerminal.spec.ts b/site/e2e/tests/webTerminal.spec.ts index 969f659e99f9a..37ab01d78e0b5 100644 --- a/site/e2e/tests/webTerminal.spec.ts +++ b/site/e2e/tests/webTerminal.spec.ts @@ -3,6 +3,7 @@ import { randomUUID } from "crypto"; import { createTemplate, createWorkspace, + openTerminalWindow, startAgent, stopAgent, } from "../helpers"; @@ -33,14 +34,9 @@ test("web terminal", async ({ context, page }) => { }, ], }); - await createWorkspace(page, template); + const workspaceName = await createWorkspace(page, template); const agent = await startAgent(page, token); - - // Wait for the web terminal to open in a new tab - const pagePromise = context.waitForEvent("page"); - await page.getByTestId("terminal").click(); - const terminal = await pagePromise; - await terminal.waitForLoadState("domcontentloaded"); + const terminal = await openTerminalWindow(page, context, workspaceName); await terminal.waitForSelector("div.xterm-rows", { state: "visible",