Tool to format gherkin-ast model to gherkin string
The format function of this package provides a formatted string (gherkin document) from your AST.
In TypeScript
import {format, FormatOptions} from "gherkin-formatter";
import {Document} from "gherkin-ast";
import {load} from "gherkin-io";
const document: Document = load("./test.feature");
const options: FormatOptions = {separateStepGroups : false};
console.log(format(document, options));
// Feature: Test Feature
//
// As a user...
In JavaScript
const {format, FormatOptions} = require("gherkin-formatter");
const {Document} = require("gherkin-ast");
const {load} = require("gherkin-io");
const document = load("./test.feature");
const options = {separateStepGroups : false};
console.log(format(document, options));
// Feature: Test Feature
//
// As a user...
By passing an FormatConfig
object to format method (or other Ast type methods where it's applicable) it can be set, how feature file text is rendered.
Option | Description | Default |
---|---|---|
oneTagPerLine |
Should tags rendered separately, one by line? | false , i.e. all tag of a scenario, feature, etc will be rendered in the same line |
separateStepGroups |
Should step groups (when-then) be separated? | false |
compact |
Should empty lines be skipped, removed from the result? | false , i.e. there will be empty lines in appropriate places |
lineBreak |
The line break character(s). | \n , i.e. it uses Unix line break, to set Windows style, set \r\n |
indentation |
The indentation character(s). | ' ' , i.e. it uses two space character to add indentation where it's appropriate |
For detailed documentation see the TypeDocs documentation.