Skip to content

chore(site): add remote playwright support and script #10445

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 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 13 additions & 3 deletions site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const port = process.env.CODER_E2E_PORT
? Number(process.env.CODER_E2E_PORT)
: defaultPort;

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");
Expand Down Expand Up @@ -34,9 +36,17 @@ export default defineConfig({
use: {
baseURL: `http://localhost:${port}`,
video: "retain-on-failure",
launchOptions: {
args: ["--disable-webgl"],
},
...(wsEndpoint
? {
connectOptions: {
wsEndpoint: wsEndpoint,
},
}
: {
launchOptions: {
args: ["--disable-webgl"],
},
}),
},
webServer: {
url: `http://localhost:${port}/api/v2/deployment/config`,
Expand Down
52 changes: 52 additions & 0 deletions site/e2e/server/run_with_forward.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail

workspace=${1:-}
port=${2:-3000}

if [[ -z "${workspace}" ]]; then
echo "Usage: $0 <workspace> [port]"
exit 1
fi

# Go to site.
cd "$(dirname "$0")/../.."

echo "Running \"pnpm install\" to ensure local and remote are up-to-date..."
pnpm install

echo "Running \"playwright install\" for browser binaries..."
pnpm exec playwright install

playwright_out="$(mktemp -t playwright_server_out.XXXXXX)"

rm "$playwright_out"
mkfifo "$playwright_out"
exec 3<>"$playwright_out"

echo "Starting Playwright server..."
exec pnpm --silent exec node ./e2e/server/server.mjs 1>&3 &
playwright_pid=$!

trap '
kill $playwright_pid
exec 3>&-
rm "$playwright_out"
' EXIT

echo "Waiting for Playwright to start..."
read -r ws_endpoint <&3
if [[ ${ws_endpoint} != ws://* ]]; then
echo "Playwright failed to start."
echo "${ws_endpoint}"
cat "$playwright_out"
exit 1
fi
echo "Playwright started at ${ws_endpoint}"

ws_port=${ws_endpoint##*:}
ws_port=${ws_port%/*}

echo "Starting SSH tunnel, run test via \"pnpm run playwright:test\"..."

ssh -t -R "${ws_port}:127.0.0.1:${ws_port}" -L "${port}:127.0.0.1:${port}" coder."${workspace}" "export CODER_E2E_PORT='${port}'; export CODER_E2E_WS_ENDPOINT='${ws_endpoint}'; [[ -d site ]] && cd site; exec \"\$(grep \"\${USER}\": /etc/passwd | cut -d: -f7)\" -l"
4 changes: 4 additions & 0 deletions site/e2e/server/server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { chromium } from "@playwright/test";

const server = await chromium.launchServer({ headless: false });
console.log(server.wsEndpoint());
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"lint:types": "tsc --noEmit",
"playwright:install": "playwright install --with-deps chromium",
"playwright:test": "playwright test --config=e2e/playwright.config.ts",
"playwright:remote": "./e2e/server/run_with_forward.sh",
"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