Test results
Every flow lists acceptance criteria (AC-1, AC-2, …). A test proves a criterion when the line directly above
it says so. The Vitest reporter records the last result of each proving test, so the Grimoire can tell you which
criteria pass, which fail and which no test covers.
Prove a criterion
Section titled “Prove a criterion”Put a @proves comment on the line directly above the test:
// @proves catalog/wishlist AC-1it("adds a product to the wishlist", async () => { // ...});The format is // @proves <feature>/<flow> AC-<n>. One test proves one criterion. A criterion may have several
proving tests.
Show a criterion
Section titled “Show a criterion”A browser test can show a criterion instead of asserting it in code: the scene runs once per language of the app and
saves one screenshot each. Put a @shows comment directly above a shows() call that names the same criterion:
import { shows } from "@warlock.js/grimoire/warlock";
// @shows contact/send-message AC-2await shows(context, "contact/send-message AC-2", async ({ page, language, path }) => { await page.goto(path("/"));});GR4013 reports a @shows line that is not directly above such a call, and GR4014 one that names a flow or
criterion that does not exist. The captures, the approved images and the changes since approval are described in
Screenshots and approvals.
Add the reporter
Section titled “Add the reporter”Add it to the project’s vitest.config.ts:
import { defineConfig } from "vitest/config";import { grimoireReporter } from "@warlock.js/grimoire/vitest";
export default defineConfig({ test: { reporters: ["default", grimoireReporter()], },});The reporter works with Vitest 5. It turns on Vitest’s includeTaskLocation option itself, so a test is matched to
its @proves line by position. If you run Vitest in a way that ignores that option, the reporter falls back to the
test name.
| Option | Default | Meaning |
|---|---|---|
root | Vitest’s root, else the current folder | Project root that holds grimoire/. |
file | grimoire/book/test-results.json | Where to write the results (project-relative or absolute). |
At the end of each run the reporter writes grimoire/book/test-results.json (or file) once, atomically. It never fails the
run and adds no work while tests run. When it cannot write the file, it prints one warning and the run goes on.
The reporter does not import @warlock.js/core.
What is recorded
Section titled “What is recorded”For each proving test: the feature, flow and criterion, the test file, the full test name, the line, the outcome
(pass, fail or skip), the duration, the time of the run and a hash of the test file.
- A partial run (one file,
--related, a test name filter) replaces the results of the files it ran and keeps the results of every other file. - A skipped test keeps the last real result when the test file has not changed since.
- A run that was cut short leaves the results of unfinished files as they were.
test-results.jsonis not committed. The book builder never deletes it.
Where the tab reads the results
Section titled “Where the tab reads the results”The devtools tab reads grimoire/book/test-results.json. The file is not committed, so a deployed app has none until
you ship it. Run the tests in CI with the reporter and put the file in the deploy, then tell the panel where it is:
reporters: ["default", grimoireReporter({ file: "deploy/test-results.json" })];
// src/config/devtools.tspanels: [["@warlock.js/grimoire/devtools", { testResultsFile: "deploy/test-results.json" }]];The same path can be given to openGrimoire(root, adapter, { testResultsFile }). The tab watches the file’s modified
time, so results written after the app started show up on the next view without a restart.
When no results were ever recorded, the tab says “No test results recorded yet” and where it looked, instead of
showing every test as not run. The flow and summary routes carry results: whether a file was read, its path, when it
was written, how many @proves lines exist and how many have a result.
Criterion status
Section titled “Criterion status”| Status | Meaning |
|---|---|
pass | Every proving test passed, and the test files have not changed since. |
fail | A proving test failed in its last run. |
stale | No test failed, but a result is older than its test file (the file changed after the run). |
not-run | A proving test has no result, or was skipped. |
no-test | No @proves line names the criterion. |
Book maps, warlock scry --flow and the devtools tab show these statuses.
warlock grimoire check reads the results.
| Code | Severity | Meaning |
|---|---|---|
GR4006 | error | A test proving a criterion failed in its last run. |
GR4007 | warning | A criterion’s result is older than its test file. Run the tests again. |
GR4008 | warning | A criterion’s test did not run (or was skipped) in the last run. |
GR4009 | warning | @proves lines exist, but no results file was found. Add the reporter and run the tests, or ship the file with the deploy. One finding for the project, at the first proof. |
GR4010 | warning | The reporter saw a proving test it could not match to a result. Keep the it(...) or test(...) call on the line right under the @proves comment, with a plain string name. |
Findings of a flow whose status is proposed are shown as expected and never fail the check.