mavdi / grunt-cucumberjs

Grunt plugin for cucumber.js
MIT License
31 stars 36 forks source link

Fatal error: Unexpected token c #1

Closed jdewit closed 10 years ago

jdewit commented 10 years ago

Any idea why this may be happening?

mavdi commented 10 years ago

Hmmm not seen it before, can you provide any more info?

jdewit commented 10 years ago

I just tried again on a fresh express-seed app and it works as expected. Looks awesome. Sorry for the bother.

jdewit commented 10 years ago

This error happens if you console.log something in your cucumber step definitions.

I'm wondering if there is a way to tell the difference between report output from cucumberjs & console logging.

If so, we could print out the log in the right spot in the report and not have the test run fail.

mavdi commented 10 years ago

Cool, let me have a look. Will get back to you.

mavdi commented 10 years ago

I know why it's happening, just thinking of a decent solution now.

    cucumber.on('close', function (code) {
      var stdout = Buffer.concat(_.last(buffer));
      if(code != 0) {
        grunt.log.error('failed tests, please see the output');
        (config.format === 'html') ? publish(JSON.parse(stdout)) : grunt.log.write(stdout);
        return done(false);
      }

      publish(JSON.parse(stdout));
      return done();
    });

specifically

      publish(JSON.parse(stdout));

Problem is that console statements mix with the stdout of cucumber.js JSON output. Not sure what to do yet... any suggestions?

jdewit commented 10 years ago

Stripping out the console statements from the stdout does not appear easy. We do know what the json structure should look like so it may be possible with some crazy string parsing.

I haven't looked much into the cucumberjs source but I wonder if the console statements could be handled separately.

jdewit commented 10 years ago

Turns out it was easy. Cucumberjs outputs the console statements before the json report.

All I had to do was find the point where the cucumber report data starts and split the output.

mavdi commented 10 years ago

@jdewit just published this now as 0.3.0.