Skip to content

Commit afd090d

Browse files
committed
chore(site): add playwright:remote script
1 parent 3200b85 commit afd090d

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

site/e2e/playwright.config.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const port = process.env.CODER_E2E_PORT
66
? Number(process.env.CODER_E2E_PORT)
77
: defaultPort;
88

9+
export const wsEndpoint = process.env.CODER_E2E_WS_ENDPOINT;
10+
911
const coderMain = path.join(__dirname, "../../enterprise/cmd/coder");
1012

1113
export const STORAGE_STATE = path.join(__dirname, ".auth.json");
@@ -34,9 +36,17 @@ export default defineConfig({
3436
use: {
3537
baseURL: `http://localhost:${port}`,
3638
video: "retain-on-failure",
37-
launchOptions: {
38-
args: ["--disable-webgl"],
39-
},
39+
...(wsEndpoint
40+
? {
41+
connectOptions: {
42+
wsEndpoint: wsEndpoint,
43+
},
44+
}
45+
: {
46+
launchOptions: {
47+
args: ["--disable-webgl"],
48+
},
49+
}),
4050
},
4151
webServer: {
4252
url: `http://localhost:${port}/api/v2/deployment/config`,

site/e2e/server/run_with_forward.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
workspace=${1:-}
5+
port=${2:-3000}
6+
7+
if [[ -z "${workspace}" ]]; then
8+
echo "Usage: $0 <workspace> [port]"
9+
exit 1
10+
fi
11+
12+
# Go to site.
13+
cd "$(dirname "$0")/../.."
14+
15+
echo "Running \"pnpm install\" to ensure local and remote are up-to-date..."
16+
pnpm install
17+
18+
echo "Running \"playwright install\" for browser binaries..."
19+
pnpm exec playwright install
20+
21+
playwright_out="$(mktemp -t playwright_server_out.XXXXXX)"
22+
23+
rm "$playwright_out"
24+
mkfifo "$playwright_out"
25+
exec 3<>"$playwright_out"
26+
27+
echo "Starting Playwright server..."
28+
exec pnpm --silent exec node ./e2e/server/server.mjs 1>&3 &
29+
playwright_pid=$!
30+
31+
trap '
32+
kill $playwright_pid
33+
exec 3>&-
34+
rm "$playwright_out"
35+
' EXIT
36+
37+
echo "Waiting for Playwright to start..."
38+
read -r ws_endpoint <&3
39+
if [[ ${ws_endpoint} != ws://* ]]; then
40+
echo "Playwright failed to start."
41+
echo "${ws_endpoint}"
42+
cat "$playwright_out"
43+
exit 1
44+
fi
45+
echo "Playwright started at ${ws_endpoint}"
46+
47+
ws_port=${ws_endpoint##*:}
48+
ws_port=${ws_port%/*}
49+
50+
echo "Starting SSH tunnel, run test via \"pnpm run playwright:test\"..."
51+
52+
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; \"\$(grep \"\${USER}\": /etc/passwd | cut -d: -f7)\" -l"

site/e2e/server/server.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { chromium } from "@playwright/test";
2+
3+
const server = await chromium.launchServer({ headless: false });
4+
console.log(server.wsEndpoint());

site/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"lint:types": "tsc --noEmit",
1919
"playwright:install": "playwright install --with-deps chromium",
2020
"playwright:test": "playwright test --config=e2e/playwright.config.ts",
21+
"playwright:remote": "./e2e/server/run_with_forward.sh",
2122
"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'",
2223
"storybook": "STORYBOOK=true storybook dev -p 6006",
2324
"storybook:build": "storybook build",

0 commit comments

Comments
 (0)