Testing with rundown-cli
rundown-cli runs scripts through the same engine and pipeline as the app, so an action that works
there works on the phone. It lives in the repository’s Swift package; scripts/rundown-cli builds
and runs it from the repository root (on a Mac, where JavaScriptCore is available).
Commands
Section titled “Commands”scripts/rundown-cli validate actions/examples/github-pr.jsscripts/rundown-cli run actions/examples/github-pr.js -i repo=owner/name -i pr=1 -s token=env:GITHUB_TOKENscripts/rundown-cli test actions/examples/github-pr.js| Command | Does |
|---|---|
validate <file> |
Loads the script and prints what it declares, or every problem with its line. |
run <file> |
Runs it once against the real network and prints the log, the notifications and a text rendering of the card. |
test <file> |
Plays <name>.fixtures.json next to the script and checks every expectation. |
template <templates.json> [id [key=value …]] |
Lists the templates in a file, or fills one in and prints a config for run --config. Answers you leave out use the field’s placeholder. |
Options for run:
| Option | |
|---|---|
-i key=value |
An input value. Repeat for more. |
-s key=value, -s key=env:VAR |
A secret, given directly or read from an environment variable. |
--config f.json |
Inputs and secrets from a file. |
--state f.json |
Where to keep state and store (default: .rundown-state/). |
--reset |
Start over from no state. |
--dry-run |
Run, but save nothing. |
--json |
Print the outcome as JSON. |
run keeps state and store between invocations, so running it twice exercises change detection and
notifications, like a second run on the phone.
Add --watch (or -w) to run or test to run again whenever the script, its fixtures or its
config file changes. Output is line-buffered, so it can be piped.
To try a template against the real service:
scripts/rundown-cli template actions/examples/templates.json subreddit subreddit=swift > swift.jsonscripts/rundown-cli run actions/examples/rss-new-entry.js --config swift.jsonFixture files
Section titled “Fixture files”test plays <name>.fixtures.json: the suite’s inputs and secrets, then a list of runs. State
and store carry over from run to run, as in the app. Each run may have:
| Field | |
|---|---|
name |
Shown in the output. |
now |
The run’s time (ISO 8601), which the script sees as ctx.now. |
inputs |
Input values that change from this run on, as when the user edits the item. |
secrets |
Secrets that change from this run on; "" removes one. |
http |
Recorded exchanges (below). |
sockets |
Recorded connections (below). |
expect |
What the run must produce (below). |
Recorded HTTP
Section titled “Recorded HTTP”{ "request": { "method": "GET", "url": "https://api.example.com/x", "headers": { "Authorization": "Bearer k" } }, "response": { "status": 200, "headers": { "etag": "\"1\"" }, "json": { "value": 42 } } }Requests are matched by method and URL, in any order. Headers in the request are checked (names are
case-insensitive). A response has json, body (text) or error (a network failure).
Recorded sockets
Section titled “Recorded sockets”{ "host": "imap.example.com", "port": 993, "tls": true, "greeting": "* OK ready", "exchanges": [{ "expect": "a1 LOGIN", "reply": ["a1 OK logged in"] }] }The server sends greeting first. Each write must contain the next exchange’s expect, after
which its reply can be read. greeting and reply are text, or an array of lines that each get
\r\n. When the replies run out, the server has closed the connection. error makes the connection
fail.
Expectations
Section titled “Expectations”| Field | Passes when |
|---|---|
notifications |
Exactly this many notifications, each matched as a subset. |
summary, state, store |
They contain these values (subsets; null means “absent”). |
error |
The run fails with a message containing this text. |
errorKind |
The run fails with this kind. |
warnings |
These texts appear in the run log’s warnings. |
Requests, connections and writes that no recording matches, and recordings that were never used, fail the run. The bundled examples all have complete suites to learn from.
Type checking
Section titled “Type checking”The typings in sdk/rundown.d.ts describe the whole contract. Start a script with:
// @ts-check/// <reference path="../../sdk/rundown.d.ts" />and VS Code (or tsc --checkJs) checks it as you type. In the Actions folder, jsconfig.json does
this for you.