0

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

Sreehari
  • 5,621
  • 2
  • 25
  • 59
Sim_8
  • 56
  • 4

1 Answers1

0

I'm not sure but I think it's exactly as it means. That function 'registerListener' doesn't exist. Did you write that method? because it's bind to your JsonOutputHook. You could also check /cucumber/lib/listener to see if that method is there. Also if you are use atom as a text editor you can search the project for that method.(I'm pretty sure other text editors might have this feature as well). As for how you can call the hook that should be in the marvelous documentation found on their git repo (https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md).