@@ -12,9 +12,22 @@ schema =
1212 type: { :in , browsers } ,
1313 type_doc: "`#{ Enum . map_join ( browsers , " | " , & ":#{ & 1 } " ) } `"
1414 ] ,
15+ runner: [
16+ default: "npx" ,
17+ type_spec: quote ( do: binary ( ) ) ,
18+ type_doc: "`t:binary/0`" ,
19+ type: { :custom , PhoenixTest.Playwright.Config , :__validate_runner__ , [ ] } ,
20+ doc:
21+ "The JS package runner to use to run the Playwright CLI. Accepts either a binary executable exposed in PATH or the absolute path to it."
22+ ] ,
23+ assets_dir: [
24+ default: "./assets" ,
25+ type: :string ,
26+ doc: "The directory where the JS assets are located and the Playwright CLI is installed."
27+ ] ,
1528 cli: [
16- default: "assets/node_modules/playwright/cli.js" ,
17- type: :string
29+ type: { :custom , PhoenixTest.Playwright.Config , :__validate_cli__ , [ ] } ,
30+ deprecated: "Use `assets_dir` instead."
1831 ] ,
1932 executable_path: [
2033 type: :string ,
@@ -65,7 +78,7 @@ schema =
6578 accept_dialogs: [
6679 default: true ,
6780 type: :boolean ,
68- doc: "Accept browser dialogs (`alert()`, `confirm()`, `prompt()`"
81+ doc: "Accept browser dialogs (`alert()`, `confirm()`, `prompt()`) "
6982 ]
7083 )
7184
@@ -119,4 +132,26 @@ defmodule PhoenixTest.Playwright.Config do
119132
120133 defp normalize ( :screenshot , true ) , do: NimbleOptions . validate! ( [ ] , @ screenshot_opts_schema )
121134 defp normalize ( _key , value ) , do: value
135+
136+ def __validate_runner__ ( runner ) do
137+ if executable = System . find_executable ( runner ) do
138+ { :ok , executable }
139+ else
140+ message = """
141+ could not find runner executable at `#{ runner } `.
142+
143+ To resolve this please
144+ 1. Install a JS package runner like `npx` or `bunx`
145+ 2. Configure the preferred runner in `config/test.exs`, e.g.: `config :phoenix_test, playwright: [runner: "npx"]`
146+ 3. Ensure either the runner is in your PATH or the `runner` value is a absolute path to the executable (e.g. `Path.absname("_build/bun")`)
147+ """
148+
149+ { :error , message }
150+ end
151+ end
152+
153+ def __validate_cli__ ( _cli ) do
154+ { :error ,
155+ "it is deprecated. Use `assets_dir` instead if you want to customize the Playwright installation directory path and remove the `cli` option." }
156+ end
122157end
0 commit comments