Skip to content

Commit

Permalink
Test Ecto sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ftes committed Nov 4, 2024
1 parent 48bb144 commit 8c9cbe7
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 42 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ permissions:

jobs:
test:
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: phoenix_test_test
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest
name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
Expand Down Expand Up @@ -75,8 +88,11 @@ jobs:
- name: Build assets for browser tests
run: mix do assets.setup, assets.build

- name: Setup database
run: mix ecto.setup

- name: Install playwright browsers
run: npm exec --prefix priv/static/assets playwright install --with-deps

- name: Run tests
run: "mix test || if [[ $? = 2 ]]; then mix test --failed; else false; fi"
run: "mix test || if [[ $? = 2 ]]; then mix test --failed; else false; fi"
14 changes: 13 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Config

config :phoenix_test, :endpoint, PhoenixTest.Endpoint
config :phoenix_test,
endpoint: PhoenixTest.Endpoint,
ecto_repos: [PhoenixTest.Repo],
otp_app: :phoenix_test,
playwright_cli: "priv/static/assets/node_modules/playwright/cli.js"

config :logger, level: :warning

Expand All @@ -20,3 +24,11 @@ config :esbuild,
cd: Path.expand("../test/assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]

config :phoenix_test, PhoenixTest.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "phoenix_test_test#{System.get_env("MIX_TEST_PARTITION")}",
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: 10
50 changes: 25 additions & 25 deletions lib/phoenix_test/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ defmodule PhoenixTest.Case do
@moduledoc """
ExUnit case module to assist with browser based tests.
See `PhoenixTest.Playwright` for more information.
## Configuration
Set browser launch options via a `@moduletag` or `setup_all`:application
```ex
@moduletag playwright: [browser: :chromium, headless: false, slowMo: 1000]
```
You can opt out of Playwright for selected tests via tags:
```ex
describe "part of feature without javascript"
@describetag playwright: false
test "regular dead or live view without javascript" do
"""

use ExUnit.CaseTemplate
Expand Down Expand Up @@ -67,6 +52,9 @@ defmodule PhoenixTest.Case do
@moduledoc false
import PhoenixTest.Playwright.Connection

@includes_ecto Code.ensure_loaded?(Ecto.Adapters.SQL.Sandbox) &&
Code.ensure_loaded?(Phoenix.Ecto.SQL.Sandbox)

def launch_browser(opts) do
opts = Map.new(opts)
ensure_started(opts)
Expand All @@ -76,7 +64,8 @@ defmodule PhoenixTest.Case do
end

def start_session(%{browser_id: browser_id} = context) do
params = browser_context_params(context)
user_agent = checkout_ecto_repos(context[:async])
params = if user_agent, do: %{userAgent: user_agent}, else: %{}
context_id = sync_post(guid: browser_id, method: "newContext", params: params).result.context.guid
on_exit(fn -> post(guid: context_id, method: "close") end)

Expand All @@ -86,16 +75,27 @@ defmodule PhoenixTest.Case do
PhoenixTest.Playwright.build(frame_id)
end

if Code.ensure_loaded?(Phoenix.Ecto.SQL.Sandbox) do
defp browser_context_params(%{repo: repo} = context) do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(repo, shared: not context[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(repo, pid)
encoded = {:v1, metadata} |> :erlang.term_to_binary() |> Base.url_encode64()
%{userAgent: "BeamMetadata (#{encoded})"}
if @includes_ecto do
def checkout_ecto_repos(async?) do
otp_app = Application.fetch_env!(:phoenix_test, :otp_app)
repos = Application.fetch_env!(otp_app, :ecto_repos)

repos
|> Enum.map(&checkout_ecto_repo(&1, async?))
|> Phoenix.Ecto.SQL.Sandbox.metadata_for(self())
|> Phoenix.Ecto.SQL.Sandbox.encode_metadata()
end
end

defp browser_context_params(_), do: %{}
defp checkout_ecto_repo(repo, async?) do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(repo)
unless async?, do: Ecto.Adapters.SQL.Sandbox.mode(repo, {:shared, self()})

repo
end
else
def checkout_ecto_repos(_) do
nil
end
end
end
end
15 changes: 8 additions & 7 deletions lib/phoenix_test/playwright.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ defmodule PhoenixTest.Playwright do
> This feature is experimental.
> If you don't need browser based tests, see `m:PhoenixTest#module-usage` on regular usage.
Test driver to run tests in an actual (usually headless) browser via [Playwright](https://playwright.dev/).
Run tests tests in a one or more browsers via [Playwright](https://playwright.dev/).
## Setup
1. Install [playwright](https://www.npmjs.com/package/playwright)
1. Install or vendor [playwright](https://www.npmjs.com/package/playwright) using your existing JS pipeline
2. Install playwright browsers: `npm exec --prefix assets playwright install --with-deps`
3. Add to `config/test.exs`: `config :phoenix_test, playwright_cli: "assets/node_modules/playwright/cli.js"`
4. Add to `test/test_helpers.exs`: `Application.put_env(:phoenix_test, :base_url, YourWeb.Endpoint.url())`
3. Add to `config/test.exs`: `config :phoenix_test, otp_app: :your_app, playwright_cli: "assets/node_modules/playwright/cli.js"`
4. Add to `test/test_helpers.exs`: `Application.put_env(:phoenix_test, :base_url, YourAppWeb.Endpoint.url())`
## Usage
Expand Down Expand Up @@ -60,12 +60,13 @@ defmodule PhoenixTest.Playwright do
## Ecto SQL.Sandbox
Pass the `repo` option to enable Ecto sandboxing.
This allows for concurrent browser tests (based on [this guide](https://hexdocs.pm/phoenix_ecto/main.html#concurrent-browser-tests)).
`PhoenixTest.Case` automatically takes care of this.
It passes a user agent referencing your Ecto repos.
This allows for [concurrent browser tests](https://hexdocs.pm/phoenix_ecto/main.html#concurrent-browser-tests).
```ex
defmodule MyTest do
use PhoenixTest.Case, async: true, repo: MyApp.Repo
use PhoenixTest.Case, async: true
```
"""

Expand Down
7 changes: 1 addition & 6 deletions lib/phoenix_test/playwright/port.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule PhoenixTest.Playwright.Port do
]

def open(config) do
cli = Map.get(config, :driver_path, default_cli())
cli = Map.get_lazy(config, :driver_path, fn -> Application.fetch_env!(:phoenix_test, :playwright_cli) end)
cmd = "run-driver"
port = Port.open({:spawn, "#{cli} #{cmd}"}, [:binary])

Expand All @@ -36,11 +36,6 @@ defmodule PhoenixTest.Playwright.Port do
{state, msgs}
end

defp default_cli do
fallback = Path.join(:code.priv_dir(:phoenix_test), "static/driver.js")
Application.get_env(:phoenix_test, :playwright_cli, fallback)
end

defp deserialize(json) do
case Jason.decode(json) do
{:ok, data} -> atom_keys(data)
Expand Down
9 changes: 8 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ defmodule PhoenixTest.MixProject do
{:mime, ">= 1.0.0", optional: true},
{:phoenix, "~> 1.7.10"},
{:phoenix_live_view, "~> 0.20.1"},
{:ecto, "~> 3.12", optional: true},
{:ecto_sql, "~> 3.12", optional: true},
{:phoenix_ecto, "~> 4.6", optional: true},
{:postgrex, "~> 0.19.2", option: true},
{:plug_cowboy, "~> 2.7", only: :test, runtime: false},
{:styler, "~> 0.11", only: [:dev, :test], runtime: false}
]
Expand Down Expand Up @@ -77,7 +81,10 @@ defmodule PhoenixTest.MixProject do

defp aliases do
[
setup: ["deps.get", "assets.setup", "assets.build"],
setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"],
"ecto.setup": ["ecto.create", "ecto.migrate"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
"assets.setup": ["esbuild.install --if-missing"],
"assets.build": ["esbuild default"]
]
Expand Down
8 changes: 7 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"cowboy": {:hex, :cowboy, "2.12.0", "f276d521a1ff88b2b9b4c54d0e753da6c66dd7be6c9fca3d9418b561828a3731", [:make, :rebar3], [{:cowlib, "2.13.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "8a7abe6d183372ceb21caa2709bec928ab2b72e18a3911aa1771639bef82651e"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.13.0", "db8f7505d8332d98ef50a3ef34b34c1afddec7506e4ee4dd4a3a266285d282ca", [:make, :rebar3], [], "hexpm", "e1e1284dc3fc030a64b1ad0d8382ae7e99da46c3246b815318a4b848873800a4"},
"db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"ecto": {:hex, :ecto, "3.12.4", "267c94d9f2969e6acc4dd5e3e3af5b05cdae89a4d549925f3008b2b7eb0b93c3", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ef04e4101688a67d061e1b10d7bc1fbf00d1d13c17eef08b71d070ff9188f747"},
"ecto_sql": {:hex, :ecto_sql, "3.12.1", "c0d0d60e85d9ff4631f12bafa454bc392ce8b9ec83531a412c12a0d415a3a4d0", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.12", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "aff5b958a899762c5f09028c847569f7dfb9cc9d63bdb8133bff8a5546de6bf5"},
"esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"},
"ex_doc": {:hex, :ex_doc, "0.32.1", "21e40f939515373bcdc9cffe65f3b3543f05015ac6c3d01d991874129d173420", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5142c9db521f106d61ff33250f779807ed2a88620e472ac95dc7d59c380113da"},
"floki": {:hex, :floki, "0.35.2", "87f8c75ed8654b9635b311774308b2760b47e9a579dabf2e4d5f1e1d42c39e0b", [:mix], [], "hexpm", "6b05289a8e9eac475f644f09c2e4ba7e19201fd002b89c28c1293e7bd16773d9"},
Expand All @@ -17,13 +21,15 @@
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"phoenix": {:hex, :phoenix, "1.7.10", "02189140a61b2ce85bb633a9b6fd02dff705a5f1596869547aeb2b2b95edd729", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "cf784932e010fd736d656d7fead6a584a4498efefe5b8227e9f383bf15bb79d0"},
"phoenix_html": {:hex, :phoenix_html, "4.0.0", "4857ec2edaccd0934a923c2b0ba526c44a173c86b847e8db725172e9e51d11d6", [:mix], [], "hexpm", "cee794a052f243291d92fa3ccabcb4c29bb8d236f655fb03bcbdc3a8214b8d13"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.6.3", "f686701b0499a07f2e3b122d84d52ff8a31f5def386e03706c916f6feddf69ef", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.1", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "909502956916a657a197f94cc1206d9a65247538de8a5e186f7537c895d95764"},
"phoenix_html": {:hex, :phoenix_html, "4.1.1", "4c064fd3873d12ebb1388425a8f2a19348cef56e7289e1998e2d2fa758aa982e", [:mix], [], "hexpm", "f2f2df5a72bc9a2f510b21497fd7d2b86d932ec0598f0210fed4114adc546c6f"},
"phoenix_live_view": {:hex, :phoenix_live_view, "0.20.3", "8b6406bc0a451f295407d7acff7f234a6314be5bbe0b3f90ed82b07f50049878", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a8e4385e05618b424779f894ed2df97d3c7518b7285fcd11979077ae6226466b"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"},
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
"plug": {:hex, :plug, "1.15.2", "94cf1fa375526f30ff8770837cb804798e0045fd97185f0bb9e5fcd858c792a3", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02731fa0c2dcb03d8d21a1d941bdbbe99c2946c0db098eee31008e04c6283615"},
"plug_cowboy": {:hex, :plug_cowboy, "2.7.1", "87677ffe3b765bc96a89be7960f81703223fe2e21efa42c125fcd0127dd9d6b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "02dbd5f9ab571b864ae39418db7811618506256f6d13b4a45037e5fe78dc5de3"},
"plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"},
"postgrex": {:hex, :postgrex, "0.19.2", "34d6884a332c7bf1e367fc8b9a849d23b43f7da5c6e263def92784d03f9da468", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "618988886ab7ae8561ebed9a3c7469034bf6a88b8995785a3378746a4b9835ec"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"styler": {:hex, :styler, "0.11.9", "2595393b94e660cd6e8b582876337cc50ff047d184ccbed42fdad2bfd5d78af5", [:mix], [], "hexpm", "8b7806ba1fdc94d0a75127c56875f91db89b75117fcc67572661010c13e1f259"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
Expand Down
4 changes: 4 additions & 0 deletions priv/repo/migrations/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
import_deps: [:ecto_sql],
inputs: ["*.exs"]
]
2 changes: 2 additions & 0 deletions test/support/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ defmodule PhoenixTest.Endpoint do

plug Plug.MethodOverride
plug PhoenixTest.Router

plug Phoenix.Ecto.SQL.Sandbox
end
5 changes: 5 additions & 0 deletions test/support/repo.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule PhoenixTest.Repo do
use Ecto.Repo,
otp_app: :phoenix_test,
adapter: Ecto.Adapters.Postgres
end
3 changes: 3 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ExUnit.start()

{:ok, _} = Supervisor.start_link([{Phoenix.PubSub, name: PhoenixTest.PubSub}], strategy: :one_for_one)
{:ok, _} = PhoenixTest.Repo.start_link()
{:ok, _} = PhoenixTest.Endpoint.start_link()

Application.put_env(:phoenix_test, :base_url, PhoenixTest.Endpoint.url())

Ecto.Adapters.SQL.Sandbox.mode(PhoenixTest.Repo, :manual)

0 comments on commit 8c9cbe7

Please sign in to comment.