Skip to content

Commit 8a623bf

Browse files
Camsburyrschmukler
authored andcommitted
fix: properly link playwright executables
Previously were hardcoding paths and versions that we could just link directly to the test runner, which we are now doing!
1 parent 01e1001 commit 8a623bf

2 files changed

Lines changed: 33 additions & 36 deletions

File tree

shell.nix

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,32 @@ let
22
pkgs = import ./nix/pinned.nix {
33
overlays = [(import ./nix/overlays.nix)];
44
};
5+
inherit (pkgs.stdenv.hostPlatform) system;
6+
throwSystem = throw "Unsupported system: ${system}";
7+
suffix =
8+
{
9+
x86_64-linux = "linux64";
10+
aarch64-linux = "linux-arm64";
11+
x86_64-darwin = "mac64";
12+
aarch64-darwin = "mac-arm64";
13+
}.${system} or throwSystem;
514
in
615
with pkgs;
716
mkShell {
17+
nativeBuildInputs = [
18+
playwright-driver.browsers
19+
];
820
buildInputs = [
921
babashka
1022
clojure
1123
cljfmt
1224
clj-kondo
1325
neil
14-
15-
# Needed for Playwright (wally) e2e tests on NixOS.
16-
# Playwright Java ships its own node binary, which is dynamically linked
17-
# and won't run on NixOS by default; we point Playwright at Nix's node and
18-
# use Nix's Chromium binary.
19-
nodejs
20-
chromium
2126
];
22-
23-
shellHook = ''
24-
# Playwright Java (via wally) runs on NixOS when we:
25-
# - prevent Playwright from downloading its own browsers (they're not Nix-patched)
26-
# - provide a "fake" Playwright browser installation that delegates to Nix's Chromium
27-
# - ensure a working Node is available
28-
29-
export PLAYWRIGHT_NODEJS_PATH="${nodejs}/bin/node"
30-
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
31-
32-
# Playwright 1.31.0 expects Chromium revision 1048 at this path.
33-
export PLAYWRIGHT_BROWSERS_PATH="$HOME/.cache/ms-playwright"
34-
chromium_dir="$PLAYWRIGHT_BROWSERS_PATH/chromium-1048/chrome-linux"
35-
mkdir -p "$chromium_dir"
36-
37-
chromium_wrapper="$chromium_dir/chrome"
38-
if [ ! -e "$chromium_wrapper" ]; then
39-
cat > "$chromium_wrapper" <<'EOF'
40-
#!/usr/bin/env bash
41-
exec "${chromium}/bin/chromium" "$@"
42-
EOF
43-
chmod +x "$chromium_wrapper"
44-
fi
45-
'';
27+
PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}";
28+
PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH = "${pkgs.playwright-driver.browsers}/chromium_headless_shell-${pkgs.playwright-driver.browsersJSON.chromium-headless-shell.revision}/chrome-headless-shell-${suffix}/chrome-headless-shell";
29+
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true;
30+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1;
31+
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE = "ubuntu-24.04";
32+
PLAYWRIGHT_NODEJS_PATH="${pkgs.nodejs}/bin/node";
4633
}

test/hyper/e2e_test.clj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
titles, and Var-based live reload of inline route handlers.
66
77
Run with: clojure -M:test --focus :e2e"
8-
(:require [clojure.test :refer [deftest is testing use-fixtures]]
8+
(:require [clojure.string :as str]
9+
[clojure.test :refer [deftest is testing use-fixtures]]
910
[hyper.core :as h]
1011
[hyper.state :as state]
1112
[wally.main :as w])
@@ -129,11 +130,20 @@
129130
;; ---------------------------------------------------------------------------
130131

131132
(defn launch-browser
132-
"Launch a headless Chromium browser. Returns {:playwright pw :browser browser}."
133+
"Launch a headless Chromium browser. Returns {:playwright pw :browser browser}.
134+
135+
If PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH is set, we launch that Chromium
136+
binary instead of Playwright's downloaded browser bundle."
133137
[]
134-
(let [pw (Playwright/create)
135-
browser (.. pw chromium (launch (doto (BrowserType$LaunchOptions.)
136-
(.setHeadless true))))]
138+
(let [pw (Playwright/create)
139+
executable-path (some-> (System/getenv "PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH")
140+
(str/trim)
141+
(not-empty))
142+
opts (doto (BrowserType$LaunchOptions.)
143+
(.setHeadless true))
144+
_ (when executable-path
145+
(.setExecutablePath opts (java.nio.file.Path/of executable-path (into-array String []))))
146+
browser (.. pw chromium (launch opts))]
137147
{:playwright pw :browser browser}))
138148

139149
(defn new-context

0 commit comments

Comments
 (0)