Skip to content
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
49 changes: 18 additions & 31 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,32 @@ let
pkgs = import ./nix/pinned.nix {
overlays = [(import ./nix/overlays.nix)];
};
inherit (pkgs.stdenv.hostPlatform) system;
throwSystem = throw "Unsupported system: ${system}";
suffix =
{
x86_64-linux = "linux64";
aarch64-linux = "linux-arm64";
x86_64-darwin = "mac64";
aarch64-darwin = "mac-arm64";
}.${system} or throwSystem;
in
with pkgs;
mkShell {
nativeBuildInputs = [
playwright-driver.browsers
];
buildInputs = [
babashka
clojure
cljfmt
clj-kondo
neil

# Needed for Playwright (wally) e2e tests on NixOS.
# Playwright Java ships its own node binary, which is dynamically linked
# and won't run on NixOS by default; we point Playwright at Nix's node and
# use Nix's Chromium binary.
nodejs
chromium
];

shellHook = ''
# Playwright Java (via wally) runs on NixOS when we:
# - prevent Playwright from downloading its own browsers (they're not Nix-patched)
# - provide a "fake" Playwright browser installation that delegates to Nix's Chromium
# - ensure a working Node is available

export PLAYWRIGHT_NODEJS_PATH="${nodejs}/bin/node"
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

# Playwright 1.31.0 expects Chromium revision 1048 at this path.
export PLAYWRIGHT_BROWSERS_PATH="$HOME/.cache/ms-playwright"
chromium_dir="$PLAYWRIGHT_BROWSERS_PATH/chromium-1048/chrome-linux"
mkdir -p "$chromium_dir"

chromium_wrapper="$chromium_dir/chrome"
if [ ! -e "$chromium_wrapper" ]; then
cat > "$chromium_wrapper" <<'EOF'
#!/usr/bin/env bash
exec "${chromium}/bin/chromium" "$@"
EOF
chmod +x "$chromium_wrapper"
fi
'';
PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}";
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";
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true;
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1;
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE = "ubuntu-24.04";
PLAYWRIGHT_NODEJS_PATH="${pkgs.nodejs}/bin/node";
}
20 changes: 15 additions & 5 deletions test/hyper/e2e_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
titles, and Var-based live reload of inline route handlers.

Run with: clojure -M:test --focus :e2e"
(:require [clojure.test :refer [deftest is testing use-fixtures]]
(:require [clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]]
[hyper.core :as h]
[hyper.state :as state]
[wally.main :as w])
Expand Down Expand Up @@ -129,11 +130,20 @@
;; ---------------------------------------------------------------------------

(defn launch-browser
"Launch a headless Chromium browser. Returns {:playwright pw :browser browser}."
"Launch a headless Chromium browser. Returns {:playwright pw :browser browser}.

If PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH is set, we launch that Chromium
binary instead of Playwright's downloaded browser bundle."
[]
(let [pw (Playwright/create)
browser (.. pw chromium (launch (doto (BrowserType$LaunchOptions.)
(.setHeadless true))))]
(let [pw (Playwright/create)
executable-path (some-> (System/getenv "PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH")
(str/trim)
(not-empty))
opts (doto (BrowserType$LaunchOptions.)
(.setHeadless true))
_ (when executable-path
(.setExecutablePath opts (java.nio.file.Path/of executable-path (into-array String []))))
browser (.. pw chromium (launch opts))]
{:playwright pw :browser browser}))

(defn new-context
Expand Down
Loading