PhxDemo.Fixtures (phx_demo v0.1.1)

Copy Markdown View Source

Finds the files that upload/4 and drop_files/4 attach.

Relative paths resolve from test/demos/fixtures/ (change it with config :phx_demo, :fixtures_dir, "path", relative to the project root). A leading fixtures/ is accepted too, so "report.pdf" and "fixtures/report.pdf" mean the same file. Absolute paths are used as-is.

PhxDemo.Case checks every literal path in a demo before the browser starts (see literal_paths/1), so a missing file fails the run up front. Paths computed at runtime are checked when the step runs.

Summary

Functions

Raises PhxDemo.Env.Error naming every missing file.

The fixtures directory, absolute.

Fixture paths written literally in a demo's AST: the path argument of upload, drop_files, upload_audio and use_microphone calls, piped or not. Used at compile time.

The absolute path for a fixture, without checking that it exists.

Absolute paths for one or many fixtures. Raises PhxDemo.Env.Error if any is missing.

Functions

check!(files)

Raises PhxDemo.Env.Error naming every missing file.

dir()

The fixtures directory, absolute.

literal_paths(ast)

Fixture paths written literally in a demo's AST: the path argument of upload, drop_files, upload_audio and use_microphone calls, piped or not. Used at compile time.

iex> ast = quote do
...>   conn |> upload("#doc", "a.pdf") |> drop_files("#zone", ["b.png", "c.csv"], picker: true)
...>   upload(conn, {:label, "Doc"}, "d.pdf")
...>   conn |> upload_audio("#a", "e.wav") |> use_microphone("f.mp3", loop: true)
...> end
iex> ast |> PhxDemo.Fixtures.literal_paths() |> Enum.sort()
["a.pdf", "b.png", "c.csv", "d.pdf", "e.wav", "f.mp3"]

path(file)

The absolute path for a fixture, without checking that it exists.

iex> PhxDemo.Fixtures.path("/tmp/a.pdf")
"/tmp/a.pdf"
iex> PhxDemo.Fixtures.path("fixtures/a.pdf") == PhxDemo.Fixtures.path("a.pdf")
true

resolve!(files)

Absolute paths for one or many fixtures. Raises PhxDemo.Env.Error if any is missing.