New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grunt-cucumberjs

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-cucumberjs - npm Package Compare versions

Comparing version 0.5.2 to 0.7.0

lib/processHandler.js

52

features/step_definitions/test.js
var assert = require('assert');
var steps = function() {
this.Given(/^I have a test scenario$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Given(/^I have a test scenario$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Given(/^I want to create test a feature$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Given(/^I want to create test a feature$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Given(/^the future is testable$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Given(/^the future is testable$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
this.When(/^I choose "([^"]*)" output$/, function(arg1, callback) {
// express the regexp above with the code you wish you had
callback();
});
this.When(/^I choose "([^"]*)" output$/, function(arg1, callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Then(/^I should see an "([^"]*)"$/, function(arg1, callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Then(/^I should see an "([^"]*)"$/, function(arg1, callback) {
// express the regexp above with the code you wish you had
callback();
});
this.Then(/^the output should contain test results$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
}
this.Then(/^the output should contain test results$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
};
module.exports = steps;
module.exports = steps;

@@ -13,45 +13,50 @@ /*

// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js'
],
options: {
jshintrc: '.jshintrc',
},
},
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'package.json',
'tasks/*.js',
'features/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp']
},
// Configuration to be run (and then tested).
cucumberjs: {
// Configuration to be run (and then tested).
cucumberjs: {
options: {
steps: '',
tags: '',
templateDir: 'templates/simple',
output: 'tmp/features_report.html',
format: 'html',
cucumber: ''
},
features : []
}
options: {
steps: '',
tags: '',
templateDir: 'templates/simple',
output: 'tmp/features_report.html',
format: 'html',
cucumber: ''
},
features: []
},
jsbeautifier: {
src: ['<%= jshint.all %>']
}
});
});
// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-jsbeautifier');
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'jsbeautifier', 'cucumberjs']);
// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'cucumberjs']);
};
{
"name": "grunt-cucumberjs",
"description": "Generates documentation from Cucumber features",
"version": "0.5.2",
"homepage": "https://github.com/mavdi/grunt-cucumberjs",
"author": {
"name": "Mehdi Avdi",
"email": "mehdi.avdi@gmail.com"
},
"repository": {
"type": "git",
"url": "git://github.com/mavdi/grunt-cucumberjs.git"
},
"contributors" : [
{ "name" : "Andrew Keig",
"email" : "andrew.keig@gmail.com",
"url" : "https://github.com/AndrewKeig"
"name": "grunt-cucumberjs",
"description": "Generates documentation from Cucumber features",
"version": "0.7.0",
"homepage": "https://github.com/mavdi/grunt-cucumberjs",
"author": {
"name": "Mehdi Avdi",
"email": "mehdi.avdi@gmail.com"
},
{ "name" : "Jozz Hart",
"email" : "me@jozzhart.com",
"url" : "http://jozzhart.com"
"repository": {
"type": "git",
"url": "git://github.com/mavdi/grunt-cucumberjs.git"
},
"contributors": [{
"name": "Andrew Keig",
"email": "andrew.keig@gmail.com",
"url": "https://github.com/AndrewKeig"
}, {
"name": "Jozz Hart",
"email": "me@jozzhart.com",
"url": "http://jozzhart.com"
}],
"bugs": {
"url": "https://github.com/mavdi/grunt-cucumberjs/issues"
},
"licenses": [{
"type": "MIT",
"url": "https://github.com/mavdi/grunt-cucumberjs/blob/master/LICENSE-MIT"
}],
"main": "Gruntfile.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt"
},
"devDependencies": {
"cucumber": "^0.4.8",
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-jsbeautifier": "^0.2.10"
},
"peerDependencies": {
"grunt": "~0.4.5"
},
"keywords": [
"gruntplugin"
],
"dependencies": {
"handlebars": "~1.0.12",
"underscore": "~1.5.2",
"commondir": "~0.0.1"
}
],
"bugs": {
"url": "https://github.com/mavdi/grunt-cucumberjs/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/mavdi/grunt-cucumberjs/blob/master/LICENSE-MIT"
}
],
"main": "Gruntfile.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-cli": "~0.1.13",
"grunt": "~0.4.5"
},
"peerDependencies": {
"grunt": "~0.4.5"
},
"keywords": [
"gruntplugin"
],
"dependencies": {
"cucumber": "~0.3.1",
"handlebars": "~1.0.12",
"underscore": "~1.5.2",
"commondir": "~0.0.1"
}
}

@@ -126,2 +126,9 @@ # grunt-cucumberjs

#### options.debugger
Type: `Boolean`
Default: `'false'`
Available: `['true', 'false']`
A flag to enabling debuggin from IDE like WebStorm. Limitation of this flag is it only does not support the HTML output, yet ;)
### Attaching Screenshots to grunt-cucumberjs HTML report

@@ -128,0 +135,0 @@

/*
* grunt-cucumberjs
* https://github.com/mavdi/grunt-cucumberjs
*
* Copyright (c) 2013 Mehdi Avdi
* Licensed under the MIT license.
*/
* grunt-cucumberjs
* https://github.com/mavdi/grunt-cucumberjs
*
* Copyright (c) 2013 Mehdi Avdi
* Licensed under the MIT license.
*/
'use strict';
var fs = require('fs');
module.exports = function(grunt) {
grunt.registerMultiTask('cucumberjs', 'Run cucumber.js features', function() {
var done = this.async();
var version = grunt.file.readJSON('./package.json').version;
var projectPkg = grunt.file.readJSON('package.json');
var spawn = require('child_process').spawn;
var _ = require('underscore');
var commondir = require('commondir');
var WIN32_BIN_PATH = '.\\node_modules\\.bin\\cucumber-js.cmd';
var UNIX_BIN_PATH = './node_modules/cucumber/bin/cucumber.js';
grunt.registerMultiTask('cucumberjs', 'Run cucumber.js features', function() {
var done = this.async();
var options = this.options({
output: 'features_report.html',
format: 'html',
saveJson: false,
theme: 'foundation',
templateDir: 'features/templates',
tags: '',
require: '',
debug: false
});
// resolve options set via cli
for (var key in options) {
if (grunt.option(key)) {
options[key] = grunt.option(key);
}
}
var commands = [];
if (options.steps) {
commands.push('-r', options.steps);
}
if (options.tags) {
if (options.tags instanceof Array) {
options.tags.forEach(function(element, index, array) {
commands.push('-t', element);
var options = this.options({
output: 'features_report.html',
format: 'html',
saveJson: false,
theme: 'foundation',
templateDir: 'features/templates',
tags: '',
require: '',
debug: false,
debugger: false
});
} else {
commands.push('-t', options.tags);
}
}
if (options.format === 'html') {
commands.push('-f', 'json');
} else {
commands.push('-f', options.format);
}
var handler = options.debugger ? require('../lib/requireHandler') : require('../lib/processHandler');
if (options.require) {
if (options.require instanceof Array) {
options.require.forEach(function(element, index, array) {
commands.push('--require', element);
});
} else {
commands.push('--require', options.require);
}
}
// resolve options set via cli
for (var key in options) {
if (grunt.option(key)) {
options[key] = grunt.option(key);
}
}
if(grunt.option('require')) {
commands.push('--require', grunt.option('require'));
}
var commands = [];
if (grunt.option('features')) {
commands.push(grunt.option('features'));
} else {
this.files.forEach(function(f) {
f.src.forEach(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return;
}
if (options.steps) {
commands.push('-r', options.steps);
}
commands.push(filepath);
});
});
}
if (options.tags) {
if (options.tags instanceof Array) {
options.tags.forEach(function(element, index, array) {
commands.push('-t', element);
});
} else {
commands.push('-t', options.tags);
}
}
var buffer = [];
var cucumber;
var binPath = '';
if (options.format === 'html') {
commands.push('-f', 'json');
} else {
commands.push('-f', options.format);
}
if (process.platform === 'win32') {
binPath = WIN32_BIN_PATH;
} else {
binPath = UNIX_BIN_PATH;
}
if(!grunt.file.exists(binPath)) {
grunt.log.error('cucumberjs binary not found at path ' + binPath + '\n NOTE: You cannot install grunt-cucumberjs without bin links on windows');
return done(false);
}
cucumber = spawn(binPath, commands);
cucumber.stdout.on('data', function(data) {
if (options.format === 'html') {
if (options.debug) {
process.stdout.write(data);
if (options.require) {
if (options.require instanceof Array) {
options.require.forEach(function(element, index, array) {
commands.push('--require', element);
});
} else {
commands.push('--require', options.require);
}
}
buffer.push(data);
} else {
grunt.log.write(data);
}
});
cucumber.stderr.on('data', function (data) {
if (options.debug) {
process.stdout.write(data);
}
var stderr = new Buffer(data);
grunt.log.error(stderr.toString());
});
cucumber.on('close', function (code) {
if (options.format === 'html') {
var featureJsonOutput;
var output = Buffer.concat(buffer).toString();
var featureStartIndex = output.substring(0, output.indexOf('"keyword": "Feature"')).lastIndexOf('[');
var logOutput = output.substring(0, featureStartIndex - 1);
var featureOutput = output.substring(featureStartIndex);
try {
featureJsonOutput = JSON.parse(featureOutput);
} catch (e) {
grunt.log.error('Unable to parse cucumberjs output into json.');
return done(false);
if (grunt.option('require')) {
commands.push('--require', grunt.option('require'));
}
generateReport(featureJsonOutput, logOutput);
}
if (grunt.option('features')) {
commands.push(grunt.option('features'));
} else {
this.files.forEach(function(f) {
f.src.forEach(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return;
}
if (code !== 0) {
grunt.log.error('failed tests, please see the output');
return done(false);
} else {
return done();
}
});
/**
* Adds passed/failed properties on features/scenarios
*
* @param {object} suite The test suite object
*/
var setStats = function(suite) {
var features = suite.features;
var rootDir = commondir(_.pluck(features, 'uri'));
var scrshotDir;
if(options.output.lastIndexOf('/')>-1) {
scrshotDir = options.output.substring(0, options.output.lastIndexOf('/')) + '/screenshot/';
} else {
scrshotDir = 'screenshot/';
}
features.forEach(function(feature) {
feature.passed = 0;
feature.failed = 0;
feature.relativeFolder = feature.uri.slice(rootDir.length);
if(!feature.elements) {
return;
commands.push(filepath);
});
});
}
feature.elements.forEach(function(element) {
element.passed = 0;
element.failed = 0;
element.notdefined = 0;
element.skipped = 0;
element.steps.forEach(function(step) {
if (step.embeddings !== undefined) {
if(!fs.existsSync(scrshotDir)){
fs.mkdirSync(scrshotDir);
}
var stepData = step.embeddings[0],
name= step.name && step.name.split(' ').join('_')|| step.keyword.trim(),
name = name + Math.round(Math.random() * 10000) + '.png', //randomize the file name
filename = scrshotDir + name;
fs.writeFile(filename, new Buffer(stepData.data, 'base64'), function(err) {
if(err){
console.error('Error saving screenshot '+filename); //asynchronously save screenshot
}
});
step.image = 'screenshot/'+ name;
handler(grunt, options, commands, function handlerCallback(err) {
if (err) {
grunt.log.error('failed tests, please see the output');
return done(false);
} else {
return done();
}
if(!step.result) {
return 0;
}
if(step.result.status === 'passed') {
return element.passed++;
}
if(step.result.status === 'failed') {
return element.failed++;
}
if(step.result.status === 'undefined') {
return element.notdefined++;
}
element.skipped ++;
});
if(element.failed > 0) {
return feature.failed++;
}
if (element.passed > 0) {
return feature.passed++;
}
});
if(feature.failed > 0) {
return suite.failed++;
}
if(feature.passed > 0) {
return suite.passed++;
}
});
suite.features = features;
return suite;
};
/**
* Returns the path of a template
*
* @param {string} name The template name
*/
var getPath = function(name) {
var path = 'node_modules/grunt-cucumberjs/templates/' + options.theme + '/' + name;
// return the users custom template if it has been defined
if (grunt.file.exists(options.templateDir + '/' + name)) {
path = options.templateDir + '/' + name;
}
return path;
};
/**
* Generate html report
*
* @param {object} featureOutput Features result object
* @param {string} logOutput Contains any console statements captured during the test run
*/
var generateReport = function(featureOutput, logOutput) {
var suite = {
name: projectPkg.name,
features: featureOutput,
passed: 0,
failed: 0,
logOutput: logOutput
};
suite = setStats(suite);
if (options.saveJson) {
grunt.file.write(options.output+'.json', JSON.stringify(featureOutput, null, '\t'));
}
grunt.file.write(
options.output,
_.template(grunt.file.read(getPath('index.tmpl')))({
suite: suite,
version: version,
time: new Date(),
features: _.template(grunt.file.read(getPath('features.tmpl')))({suite : suite, _ : _ }),
styles: grunt.file.read(getPath('style.css')),
script: grunt.file.read(getPath('script.js'))
})
);
grunt.log.writeln('Generated ' + options.output + ' successfully.');
};
});
});
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc