diff
diff(paths: string[], opts: DiffOptions, deps?: ReadsGitDiff): DiffResult compares each .feature file’s
working-tree text against its text at opts.base and classifies every scenario as added,
modified, removed, or unchanged. Each file carries an addOnly flag and the result carries
a summary {added, modified, removed, unchanged, files, addOnly} — addOnly is true when only
new scenarios were introduced and no existing one was touched. A genuine git/ref failure throws
GitError; the engine itself never prints or exits.
import { diff, GitError } from 'gherkin-cli'
try { const result = diff(['features/login.feature'], { base: 'HEAD~1' }) if (result.summary.addOnly) { console.log('purely additive change') } for (const file of result.files) { for (const scenario of file.scenarios) { console.log(scenario.change, scenario.name) } }} catch (err) { if (err instanceof GitError) { console.error(`could not resolve base ref: ${err.message}`) } else { throw err }}Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
paths | string[] | The .feature files to classify. |
opts.base | string | Base git ref to compare against (required). |
opts.full | boolean | Include unchanged scenarios in each file’s scenarios list. |
deps.readDiff | ReadsGitDiff | Injected reader for working-tree and base text (separate 3rd arg, default reads git). |
Behavior
Section titled “Behavior”- Scenario identity is the scenario name within its feature — a rename reads as add + remove.
modifiedmeans same name, but steps, tags, or examples differ.- A file absent at base is entirely additive: every scenario is
added, andaddOnlyistrue. - The default projection lists only the changed scenarios;
{ full: true }restores theunchangedrows. The classification itself is over the whole file, sosummary.unchangedand bothaddOnlyflags are computed before the projection. - An unresolvable base ref throws
GitError— the engine does not print or exit; the caller (or the CLI) catches it. - The git seam is a separate 3rd
depsargument — aReadsGitDiffrole interface with areadDiff(file, base) => { head?, base? }method — so the engine is testable without touching git. The defaultgitReadsDiffreads working-tree text from the filesystem and base text fromgit show <ref>:<path>.