This precompiler can load external data (JSON, CSV, or XLS/XLSX) into the examples table.
'use strict';
const compiler = require('gherking');
const { default: TestData } = require('gpc-test-data');
let ast = await compiler.load('./features/src/login.feature');
ast = await compiler.process(
ast,
new TestData({
defaultValue: "-"
})
);
await compiler.save('./features/dist/login.feature', ast, {
lineBreak: '\r\n'
});
'use strict';
import {load, process, save} from "gherking";
import TestData from "gpc-test-data";
let ast = await load("./features/src/login.feature");
ast = await process(
ast,
new TestData({
defaultValue: "-"
})
);
await save('./features/dist/login.feature', ast, {
lineBreak: '\r\n'
});
In the feature file, for each Examples, one of the following tags can be set:
@load_json(path)
to load the data from a JSON file@load_csv(path)
to load the data from a CSV file@load_xls(path)
to load the data from an XLS/XLSX file, from the first sheet@load_xls(path,sheet)
to load the data from an XLS/XLSX file, from the given sheet@load_http(url)
to load the data from an HTTP source (a JSON response of an object array)For each tag, the path must be either a relative (from cwd
) or an absolute path to the file, including the file name and extension.
There are some restrictions on the various data formats:
The precompiler supports the following configuration options to be set:
Option | Type | Description | Default |
---|---|---|---|
keepTag |
boolean |
Whether the load-tags should be kept or removed. | false |
defaultValue |
string|number |
The default value to be added to the table, if a column/value is not found. | "" |
appendData |
boolean |
Whether the loaded data should be appended to the existing rows of the examples table or overwritten. | true |
ignoreKeyCase |
boolean |
Whether the casing of the example columns and data columns should be ignored. | true |
addSourceComment |
boolean |
Whether a comment should be added to the example, indicating the source and the data type. | false |
allowEmptyData |
boolean |
Whether empty data files are allowed to be loaded, or error should be thrown. | false |
This package uses debug for logging, use gpc:test-data
:
DEBUG=gpc:test-data* gherking ...
For detailed documentation see the TypeDocs documentation.
Generated using TypeDoc