The run command takes an options object and a callback.
The following options are available for reporting on a test log:
type
{string} - text, json, box, plot, or html. Default is json.input
{stream} - readable stream of report data generated bygrandma.run
.output
{stream} - writable stream to output the report to. This value is optional for thejson
type is specified.metadata
{string} - used withtype: 'html'
, provides metadata that will be included in the report as plain text.box
{object} - options of the box plot type.width
{number} - the maximum width, in characters, of the box plot. Default is 75.
Json example:
var fs = require('fs');
var input = fs.createReadStream('path/to/a/grandma.log');
var grandma = require('grandma');
grandma.report({
input: input,
type: 'json'
}, function(err, jsonObj) {
if (err) {
console.error('something went horribly wrong', err);
} else {
console.log(jsonObj);
}
});
Text example printing to standard out:
var fs = require('fs');
var input = fs.createReadStream('path/to/a/grandma.log');
var output = process.stdout; // print to the console
var grandma = require('grandma');
grandma.report({
input: input,
output: output,
type: 'text'
}, function(err) {
if (err) {
console.error('something went horribly wrong', err);
} else {
console.log('the report was written to the output stream');
}
});
Plot example writing to a file:
var fs = require('fs');
var input = fs.createReadStream('path/to/a/grandma.log');
var output = fs.createWriteStream('path/to/a/report.html');
var grandma = require('grandma');
grandma.report({
input: input,
output: output,
type: 'plot'
}, function(err) {
// ...
});
HTML example, including all environment variables as metadata:
var fs = require('fs');
var input = fs.createReadStream('path/to/a/grandma.log');
var output = fs.createWriteStream('path/to/a/report.html');
var grandma = require('grandma');
grandma.report({
input: input,
output: output,
type: 'html',
metadata: JSON.stringify(process.env, null, 2)
}, function(err) {
// ...
});