From 8b375b3feeabca39f18e722e356a7669fa7aaa7c Mon Sep 17 00:00:00 2001 From: Giles Thompson Date: Thu, 12 Dec 2024 13:58:52 +1300 Subject: [PATCH] Use tmp dir in WIP file watcher test --- test/watcher_test.exs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/test/watcher_test.exs b/test/watcher_test.exs index 7e87bdc..e2ebcd1 100644 --- a/test/watcher_test.exs +++ b/test/watcher_test.exs @@ -1,12 +1,40 @@ defmodule WatcherTest do use ExUnit.Case, async: true + alias PhoenixImportmap.Util + + @moduletag :tmp_dir + @example_importmap %{ app: "/test/fixtures/js/app.js", remote: "https://cdn.es6/package.js" } - test "file watch" do - {:ok, _pid} = PhoenixImportmap.watch(@example_importmap, ~w(/test/fixtures)) + setup %{tmp_dir: tmp_dir} do + relative_tmp_dir = Util.relative_path(tmp_dir) + + Application.put_env( + :phoenix_importmap, + :copy_destination_path, + relative_tmp_dir <> "/assets" + ) + + Application.put_env(:phoenix_importmap, :public_asset_path_prefix, relative_tmp_dir) + File.mkdir_p!(tmp_dir <> "/assets") + + {:ok, pid} = + start_supervised( + {PhoenixImportmap.Watcher, + %{ + importmap: @example_importmap, + watch_dirs: ~w(/test/fixtures) + }} + ) + + %{pid: pid} + end + + test "start supervised", %{pid: pid} do + assert pid end end