Audit test coverage
doc-detective audit reports which parts of your docs a test step covers. It detects tests the same way a run does, but it runs nothing. Use it before you write your first test, and again each time you add one.
The report leads with procedure steps, because those are what readers follow. There’s no single percentage: each kind of content gets its own count.
Before you begin
- Docs in a supported format, such as Markdown, MDX, AsciiDoc, HTML, or DITA.
- Doc Detective 5 or later.
auditreads the sameinput,fileTypes,detectSteps,allowUnsafeSteps, andoriginsettings as a run.
Run an audit
-
Run
auditon your docs folder:Without an argument,
auditreads theinputfrom your config, or the current folder. -
Read the Untested procedure steps list. Each entry is a file, a line number, and the step’s text.
-
Add a test for a step, then run
auditagain to see the count change. The report ends with the statements to write for each format in the run. See Act on the report.
To get the full report as JSON, for a script or a CI summary, add --json. To print only the first line, add -q.
audit exits 0 whenever it prints a report, whatever the coverage. It exits 2 for bad usage, a bad config, or no files to audit.
How audit finds procedures
A procedure is a numbered list. audit decides whether a list is a procedure in this order:
- You marked it. A DITA
<steps>element, an MDX<Steps>component, or a list right after aprocedurestatement always counts. - At least a third of its items are instructions. A built-in grammar tagger reads each item. “Open a terminal.”, “In a terminal, run
npm test.”, “Then click Save.”, and “Create a branch: rungit checkout -b fix.” count. “Release notes” doesn’t. - Anything else goes in Possible procedures. These lists stay out of the headline, but you still see their counts.
Only a list’s top-level items are procedure steps. A nested list belongs to the item above it.
The tagger reads English. Lists in other languages land in Possible procedures, so mark the ones that are procedures.
Mark a list as a procedure
Put a procedure statement directly before the list, with nothing but blank lines between them:
What gives an item a step
Each item gets one state:
- Procedure steps. A step belongs to the item it sits in. An item runs from its marker to the next item, so put a step statement on the line after the sentence it tests. A test wrapped around a list puts its other items inside a test, but only when the test has a step that runs. An empty test, or one with only
wait, gives no credit. A test is a region that starts at ateststatement and ends attest end, or at the nextteststatement. Steps that check nothing, such aswaitandloadVariables, don’t count. - Code blocks. Only runnable languages count: shell (
bash,sh,shell,console,zsh,powershell,pwsh), Python, JavaScript, andhttp. A block has a step when detection finds a step inside it, when a step statement directly follows it, or when itsidmatches an authoredstepId. - Links. Absolute links count, and relative links count when you set
origin. A link has a step when anygoToorcheckLinkstep targets the same URL. The comparison ignores fragments and trailing slashes. - Images. An image has a step when detection finds a
screenshotstep on it, or when ascreenshotstep writes to the same file. - Pages. A page counts when it has at least one step statement you wrote.
With detectSteps: false, audit still counts every code block, link, and image. Only steps you wrote give credit.
Tag a code block
A code block can carry an id, a procedure class, or a testIgnore class:
idlinks the block to a step with the samestepId, including a step in a standalone spec.procedurecounts the block as a procedure step, even outside a numbered list.testIgnoremarks the block ignored.
A standalone spec then credits the block through the step’s stepId:
Act on the report
The text report can end with the statements to write for each format in the run. An untested procedure step brings the step, test, and ignore statements. A list in Possible procedures brings the procedure statement. With --json, the same guidance is in the guidance object, and each file’s syntax says which templates apply to it.
Cover a step
Put a step statement inside the item, on the line after the sentence it tests. Or wrap the procedure in a test with at least one step, and its other items count as inside a test.
DITA uses the <data> element, which survives every DITA-OT build.
Flag a false positive
Wrap a list that isn’t a procedure, or an item you won’t test, in test ignore start and test ignore end. Its items then count as ignored.
To skip a code block you won’t run, tag it testIgnore. See Tag a code block.
Fix a false negative
If audit puts a real procedure in Possible procedures, put a procedure statement directly before the list. See Mark a list as a procedure.
Custom file types
The guidance checks each template against the file’s own file type. A custom file type that reads the built-in statements, such as one that extends Markdown, gets the built-in templates. A file type with its own inlineStatements gets the bare statement text, such as step {"click": "Save"}. A note says to wrap it in that file type’s comment form. Its key in guidance.syntaxes is the file type’s name, or <name>-custom when that name is a built-in syntax’s, such as markdown. If another file type in the run already has that key, it’s numbered from -2.