damianszczepanik / cucumber-sandwich

Create Pretty Cucumber Reports on the Fly locally during development
60 stars 31 forks source link

Support for JavaScript? #21

Closed JimLynchCodes closed 8 years ago

JimLynchCodes commented 8 years ago

Hi. I'm looking for this exact thing but for JavaScript cucumber.js

Any plans to support that? :)

nbarrett commented 8 years ago

Hi @JimTheMan - I've managed to generate HTML reports in conjunction with cucumber-js and Protractor by adding the following grunt configuration:

in package.json: "grunt-shell": "^1.1.2", "path": "^0.12.7"

in Gruntfile (only relevant parts shown to address your requirements):

module.exports = function(grunt) {
  var path = require('path');

    // Executes shell tasks
    shell: {
      cukeReports: {
        command: function (directory) {
          var absolutePath = path.resolve('target/protractor/cucumber/reports/' + directory);
          return ['java', '-jar', path.resolve('test/cucumber/lib/cucumber-sandwich.jar'), '-f', absolutePath, '-o', absolutePath, ' -n'].join(' ');
        }
      }
    },

  grunt.registerTask('e2e-cuke', 'e2e cuke test run', function () {
    grunt.task.run([
      'protractor:cuke',
      'e2e-cuke-reports'
    ]);
  });
  grunt.registerTask('e2e-cuke-reports', 'Generate Cucumber HTML reports', function () {

    function createReportsForCapability(directory) {
      grunt.task.run('shell:cukeReports:' + path.basename(directory));
    }

    grunt.file.expand({filter: 'isDirectory'}, ['target/protractor/cucumber/reports/*']).forEach(createReportsForCapability);
  });

Not sure whether you are running Cucumber standalone or via Protractor (recommended actually) but the above task configuration produces a set of html reports per multi-capability which is pretty handy. For builds run in CI I use the 'proper' Jenkins plugin, so the above is used for getting the nice reporting from locally run tests. Oh and you'll need a JDK installed as well as the shell task uses that to make the sandwich 😄 .

damianszczepanik commented 8 years ago

I don't use the cucumber-JS implementation but if someone raises the problem or lack of support then I try to add improvement. Try to use the most recent version (where some problems has been resolved already https://github.com/damianszczepanik/cucumber-reporting/issues/467 ) and if you still have problem file the issue in cucumber-reporting project by adding JSON file