Skip to content

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.

Put a @proves comment on the line directly above the test:

// @proves catalog/wishlist AC-1
it("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.

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-2
await 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 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.

OptionDefaultMeaning
rootVitest’s root, else the current folderProject root that holds grimoire/.
filegrimoire/book/test-results.jsonWhere 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.

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.json is not committed. The book builder never deletes it.

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:

vitest.config.ts
reporters: ["default", grimoireReporter({ file: "deploy/test-results.json" })];
// src/config/devtools.ts
panels: [["@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.

StatusMeaning
passEvery proving test passed, and the test files have not changed since.
failA proving test failed in its last run.
staleNo test failed, but a result is older than its test file (the file changed after the run).
not-runA proving test has no result, or was skipped.
no-testNo @proves line names the criterion.

Book maps, warlock scry --flow and the devtools tab show these statuses.

warlock grimoire check reads the results.

CodeSeverityMeaning
GR4006errorA test proving a criterion failed in its last run.
GR4007warningA criterion’s result is older than its test file. Run the tests again.
GR4008warningA criterion’s test did not run (or was skipped) in the last run.
GR4009warning@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.
GR4010warningThe 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.