Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for writing output to file (close #90) #188

Closed
wants to merge 2 commits into from

Conversation

stejanse
Copy link

Implemented CLI argument --report for specifying a file location to which the formatter output will be written.

@samccone
Copy link
Member

samccone commented Aug 5, 2014

this PR is invalidated by #215
I think we should just put the responsibility on the end user if you want to output in a custom way.

As a side note this output redirect is quite simple using a unix pipe via the command line.

+1 to close

@jlin412
Copy link

jlin412 commented Aug 5, 2014

@samccone I am not sure that I am totally agreed. Please clarify if I understand incorrectly. For example, the currentl json formatter does not have a way to output file. Use unix pipe will include other output before and after cucumber runner. Thus, we should still have a way to output to a file from any formatter. Once it is outputted into a file, we can start customizing it.

@stejanse
Copy link
Author

stejanse commented Aug 5, 2014

I agree to @jlin412, there is no possibility to get the output of the formatter only to file. This should be made possible in Cucumber.js. I think my pull request is not perfect, but at least a working setup.

Missing this functionality is a showstopper for our Cucumber.js use (running it in Jenkins).

@samccone
Copy link
Member

samccone commented Aug 5, 2014

Ok, cool I have been convinced. Lets get the to the finish line.

So regardless of the formatter we want to redirect console.log to a file correct?

@jlin412
Copy link

jlin412 commented Aug 5, 2014

@stejanse Please excuse my ignorance. Is this the same as nicolassenechal/cucumber-js@b337b18?

@stejanse
Copy link
Author

stejanse commented Aug 5, 2014

Yes, he merged my commit into his repository.

@samccone samccone removed the invalid label Aug 5, 2014
@samccone
Copy link
Member

samccone commented Aug 5, 2014

@stejanse can you rebase this off of master please

@stejanse
Copy link
Author

stejanse commented Aug 7, 2014

I rebased the pull request.

@samccone
Copy link
Member

samccone commented Aug 7, 2014

thanks so much @stejanse :)

@jbpros
Copy link
Member

jbpros commented Aug 8, 2014

Thanks!

Could you add --report doc to --help?

I still think this should disappear once we got #215 merged in. Each plugin (or formatter) should be configurable and passed an output file path.

It will also cause troubles once we allow multiple formatters (#91) as the --report flag will make Cucumber pick the last listener output.


finish: function finish(result) {
if (configuration.getReportFile() !== null) {
fs.writeFileSync(configuration.getReportFile(), listeners.getLast().getLogs(), { flag: 'w' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to pass the flag option here since it defaults to w

http://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback

@samccone
Copy link
Member

samccone commented Aug 8, 2014

We will want to add a feature test to this also to test how it all works.
Let me know if you need help with this :)

Thanks again for the work

@dirwin517
Copy link

+1

@stejanse
Copy link
Author

I processed all feedback in this thread! Let me know if there are still some issues.

@jlin412
Copy link

jlin412 commented Aug 21, 2014

@jbpros Is it possible to have this PR merged into next minor release?

@samccone
Copy link
Member

@jlin412 that is the plan, I am planing on doing a release early next week

@jlin412
Copy link

jlin412 commented Aug 21, 2014

perfect. Though I hope that a fix for
#224 will be provided at the
same time, else it is useless when we can't use json formatter.

On Thu, Aug 21, 2014 at 9:57 AM, Sam Saccone [email protected]
wrote:

@jlin412 https://github.com/jlin412 that is the plan, I am looking at
doing a release early next week


Reply to this email directly or view it on GitHub
#188 (comment).

@stejanse
Copy link
Author

stejanse commented Sep 3, 2014

Any hold up before this can get merged?

@dirwin517
Copy link

Any news on this ? I see the Travis CI build failed?

@dirwin517
Copy link

As a work around this seems to work from AndreKanig

module.exports = function someHook() {
    var JsonFormatter = Cucumber.Listener.JsonFormatter();

    JsonFormatter.log = function (string) {
          //write out to file
    };

    this.registerListener(JsonFormatter);
 };

#205

@samccone samccone mentioned this pull request Feb 26, 2015
@robdrysdale
Copy link

Would be great to get this in. Had to add a really kludgy hack to get cucumber-js to function in jenkins where we need to pickup the cucumber json and junit formats.

var Cucumber = require('cucumber');
var CucumberJunit = require('cucumber-junit');
var cli = Cucumber.Cli(process.argv);
var fs = require('fs-extra');
var reportFileJson = "cucumber-reports/cucumber.json";
var reportFileJunit = "cucumber-reports/cucumber.xml";

var configuration = Cucumber.Cli.Configuration(process.argv);

var handler = function(succeeded) {
  var code = succeeded ? 0 : 1;

  var report = formatter.getLogs();

  fs.outputFile(reportFileJson, report, function(err) {
        if(err) {
            return console.log("Error saving report => " + err);
        }
        console.log()
        console.log("Cucumber report saved to " + reportFileJson);
        fs.outputFile(reportFileJunit, CucumberJunit(report), function(err) {
            if(err) {
                return console.log("Error saving report => " + err);
            }
            console.log("Cucumber junit report save to " + reportFileJunit);
         });
    });

  process.on('exit', function () {
    process.exit(code);
  });

  var timeoutId = setTimeout(function () {
    console.error('Cucumber process timed out after waiting 60 seconds for the node.js event loop to empty.  There may be a resource leak.  Have all resources like database connections and network connections been closed properly?');
    process.exit(code);
  }, 60 * 1000);

  if (timeoutId.unref) {
    timeoutId.unref();
  }
  else {
    clearTimeout(timeoutId);
  }
};

if (configuration.isHelpRequested()) {
  cli.displayHelp(handler);
}
else if (configuration.isVersionRequested()) {
  cli.displayVersion(handler);
}
else {
  var runtime   = Cucumber.Runtime(configuration);
  var formatter = configuration.getFormatter();
  runtime.attachListener(formatter);
  runtime.start(handler);
}

@jbpros jbpros added this to the major features milestone Jul 3, 2015
@jbpros jbpros modified the milestones: major features, 1.0 release Oct 10, 2015
@charlierudolph
Copy link
Member

closing in favor of #425

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants