Expresso.Check.Session (expresso v0.1.0)

Copy Markdown View Source

Runs --check=browser: the checks of the page in Playwright, and the keys of the presenter

--check=browser runs each check of --check=a11y, and then it uses the presenter as the presenter does, with real key presses. It needs Node, the npm packages playwright and axe-core, the Chromium of Playwright, and the Hex package playwright_ex. find/2 finds them.

run/4 writes a copy of the document with axe-core to a temporary directory, and opens it in a page of 1920 × 1080:

  1. With ?check=a11y, the page runs the layout check and axe-core. assets/src/check.ts gives the rules.
  2. With no query, the session presses the key of the next step from the first step to the last step. After each key, the slide and the step that show must be the next entry of the list of the steps.
  3. The session opens the menu, the list of keys, the overview and the handout view with their keys. Each view must open. The menu and the list of keys must take the focus, and Escape must close them and give the focus back.
  4. Each error of the script of the page, and each console.error, during the steps 2 and 3 is a problem too.

The keys come from the program of Expresso.Presenter.Default, so the check presses the keys that the list of keys of the deck shows.

Summary

Types

The tools of the session: the Playwright CLI and the axe-core file

Functions

Find the tools of --check=browser

Return the key of a mode of a program that runs a command

Run the checks of the page and the keys of the presenter on a document

Types

tools()

@type tools() :: %{cli: Path.t(), axe: Path.t()}

The tools of the session: the Playwright CLI and the axe-core file

Functions

find(directories, env \\ System.get_env())

@spec find([Path.t()], %{required(String.t()) => String.t()}) ::
  {:ok, tools()} | {:error, String.t()}

Find the tools of --check=browser

The function looks for each tool in this sequence, and it returns the error of the first tool that it does not find:

  1. The Hex package playwright_ex.
  2. Node, as node on the PATH.
  3. The npm package playwright. The variable EXPRESSO_PLAYWRIGHT in env gives the path of its cli.js. Without it, the function looks for node_modules/playwright/cli.js in each directory of directories, in each parent of them, and in the directory of Expresso.Check.Tools.
  4. axe-core, as Expresso.Check.Browser.find_axe/2 finds it.

key(program, mode, command)

Return the key of a mode of a program that runs a command

A binding with more than one key gives the key that the list of keys shows first in this sense: a letter before another key, and a short name before a long name.

iex> deck = Expresso.Builder.deck([Expresso.Builder.slide("one", elements: [])], name: "k")
iex> program = Expresso.Presenter.Program.compile(Expresso.Presenter.Definition.presenter(), deck)
iex> Expresso.Check.Session.key(program, :present, {:step, 1})
"j"
iex> Expresso.Check.Session.key(program, :present, {:set, :menu, true})
"m"

run(html, deck, tools, opts \\ [])

@spec run(String.t(), Expresso.Deck.t(), tools(), keyword()) ::
  {:ok, [{{Expresso.Check.size(), :light | :dark | nil}, map()}]}
  | {:error, String.t()}

Run the checks of the page and the keys of the presenter on a document

deck gives the list of the steps and the program of the keys. The option :schemes gives the variants of the theme, such as [:light, :dark], and [nil] by default for the variant of the document. The option :sizes gives the sizes of the page, such as [{1280, 720}], and [{1920, 1080}] by default. The page runs its checks one time for each size and each variant, and the keys run one time, at the first size and in the first variant.

The function returns a list with a tuple {{size, scheme}, result} for each size and each variant. A result holds the result of the page, as Expresso.Check.Browser.decode/1 returns it. The first result also holds the problems of the keys and of the script in :session. The option :env gives the environment, and EXPRESSO_CHROMIUM in it gives a different browser than the Chromium of Playwright.