I am quite new to cucumberjs and javascript, trying to generate a json output. Have created a hook:
have the following in my JsonOutputHook.js
module.exports = function JsonOutputHook() {
try {
var Cucumber = require('cucumber');
var JsonFormatter = Cucumber.Listener.JsonFormatter();
var fs = require('fs');
JsonFormatter.log = function (json) {
fs.writeFile('./cucumber.json', json, function (err) {
if (err) throw err;
});
};
this.registerListener(JsonFormatter);
}
catch(err){
console.log('entered hook exception);
}
};
And following in my world.js
var hooks = require('./JsonOutputHook');
//calling it like this
hooks.call(this);
But on doing so, it throws the following error:
[TypeError: this.registerListener is not a function]
Not sure why am getting this error, also how should I call the hook through my world.js.
Suggestion please.
Thanks Simit