Skip to content

gherking/gherkin-formatter

Repository files navigation

gherkin-formatter

Downloads Version@npm Version@git CI Docs

Tool to format gherkin-ast model to gherkin string

Usage

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 { read } from "gherkin-io";

const document: Document[] = await read("./test.feature");
const options: FormatOptions = {separateStepGroups: false};
console.log(format(document[0], options));
// Feature: Test Feature
//
//   As a user...

In JavaScript

const {format, FormatOptions} = require("gherkin-formatter");
const {Document} = require("gherkin-ast");
const {read} = require("gherkin-io");

const document = await read("./test.feature");
const options = {
    separateStepGroups: false
};
console.log(format(document[0], options));
// Feature: Test Feature
//
//   As a user...

Configuration - FormatConfig

Passing a FormatConfig object to format method (or other Ast type methods where it's applicable), how feature file text is rendered can be set.

Option Description Default
oneTagPerLine Should the tags be rendered separately, one by line? false, i.e., all tags 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). null, i.e., it will determine the line-break based on the platform
indentation The indentation character(s). ' ', i.e., it uses two space characters to add indentation where it's appropriate
tagFormat The tag format to be used (see gherkin-ast. TagFormat.FUNCTIONAL, i.e., the tags will be outputed as @name(value)

Other

For detailed documentation see the TypeDocs documentation.

This package uses debug for logging, use gherkin-formatter to see debug logs:

DEBUG=gherkin-formatter* node my-script.js