Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Public API

Daniel Pacak edited this page Mar 10, 2016 · 2 revisions

featurebook.commands.serve(sourceDir, port)

Equivalent of featurebook serve.

var featurebook = require('featurebook').commands;

featurebook.serve(
   'path/to/your/specification/directory',
   3000
);

featurebook.commands.build(sourceDir, format, outputDir)

Equivalent of featurebook build.

var featurebook = require('featurebook').commands;

featurebook.build(
   'path/to/your/specification/directory',
   'pdf',
   'path/to/build/output/directory'
);

Experiments with new API [NOT IMPLEMENTED YET!]

The API is accessible through the featurebook module.

var featurebook = require('featurebook');
console.log(featurebook.version); // prints the version of this API

featurebook.readFeaturesTree(specDir, callback)

Asynchronously traverses the specification directory and finds the feature files. Note that the nodes are just references to the *.feature files. We don't want to load everything into memory. To access the content of a given feature file (i.e. its description, steps, etc) you call the readFeature() function. This function is aware of .featurebookignore file and may skip some files/directories.

featurebook.readFeaturesTree('path/to/a/specs/dir', function (err, featuresTree) {
  if (err) throw err;
  console.log(featuresTree)
}

featurebook.readFeature(featureFile, callback)

Asynchronously reads a given feature and returns its object representation.

featurebook.readFeature('path/to/a/feature/file', function (err, feature) {
}

featurebook.readMetadata(specDir, callback)

Asynchronously reads a given spec metadata (featurebook.json):

featurebook.readMetadata('path/to/a/specs/dir', function (err, metadata) {
}

where metadata is:

{
  "title": "Online Banking App",
  "version": "v1.0.1",
  "authors": [{
    "firstName": "CariDee",
    "lastName": "English",
    "email": "caridee.english@icloud.com"
  }],
  "contributors": [
  ]
}

If the title property is not provided it's inferred from the specs dir name, e.g my_spec becomes My spec, or my_specs_goes_here becomes My specs goes here

featurebook.validateMetadata(specDir, callback)

Asynchronously validates the specs metadata (featurebook.json):

featurebook.validateMetadata('path/to/a/specs/dir', function (err, validationErrors) {
}

featurebook.readSummary(specDir, callback)

Asynchronously reads the specs summary (SUMMARY.md):

featurebook.readSummary('path/to/a/specs/dir', function (err, summary) {
}