Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cucumber-enhancement

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cucumber-enhancement - npm Package Compare versions

Comparing version 1.0.0 to 3.0.0

.eslintignore

56

features/step_definitions/git_branches.js

@@ -1,40 +0,38 @@

var expect = require('chai').expect;
'use strict';
module.exports = function () {
const { defineSupportCode } = require('cucumber');
const expect = require('chai').expect;
this.When(/^I list the branches$/, {
api: this.joi.string(),
token: this.joi.string(),
owner: this.joi.string(),
repo: this.joi.string()
}, function (data, callback) {
this.request({
defineSupportCode(({ When, Then }) => {
When(/^I list the branches$/, function (callback) {
const world = this;
const data = world.getAttributes({
request: world.joi.func(),
api: world.joi.string(),
owner: world.joi.string(),
repo: world.joi.string()
});
data.request({
method: 'GET',
uri: [
data.api, 'repos', data.owner, data.repo, 'branches'
].join('/'),
qs: {
access_token: data.token
}
}, function (err, message, response) {
uri: `${data.api}/repos/${data.owner}/${data.repo}/branches`
}, (err, message, response) => {
if (err) {
throw err;
return callback(err);
}
callback(null, {
branches: response.map(function (obj) {
return obj.name;
})
});
world.setAttribute('branches', response.map(obj => obj.name));
return callback();
});
});
this.Then(/^I should see "([^"]*)" as one of the branches$/, {
branches: this.joi.array()
}, function (data, branch, callback) {
Then(/^I should see "([^"]*)" as one of the branches$/, function (branch) {
const world = this;
const data = world.getAttributes({
branches: world.joi.array()
});
expect(data.branches).to.contain(branch);
setImmediate(callback);
});
};
});

@@ -1,38 +0,38 @@

var expect = require('chai').expect;
'use strict';
module.exports = function () {
const { defineSupportCode } = require('cucumber');
const expect = require('chai').expect;
this.When(/^I list the languages$/, {
api: this.joi.string(),
token: this.joi.string(),
owner: this.joi.string(),
repo: this.joi.string()
}, function (data, callback) {
this.request({
defineSupportCode(({ When, Then }) => {
When(/^I list the languages$/, function (callback) {
const world = this;
const data = world.getAttributes({
request: world.joi.func(),
api: world.joi.string(),
owner: world.joi.string(),
repo: world.joi.string()
});
data.request({
method: 'GET',
uri: [
data.api, 'repos', data.owner, data.repo, 'languages'
].join('/'),
qs: {
access_token: data.token
}
}, function (err, message, response) {
uri: `${data.api}/repos/${data.owner}/${data.repo}/languages`
}, (err, message, response) => {
if (err) {
throw err;
return callback(err);
}
callback(null, {
'languages': Object.keys(response)
});
world.setAttribute('languages', Object.keys(response));
return callback();
});
});
this.Then(/^I should see "([^"]*)" as one of the languages$/, {
languages: this.joi.array()
}, function (data, language, callback) {
Then(/^I should see "([^"]*)" as one of the languages$/, function (language) {
const world = this;
const data = world.getAttributes({
languages: world.joi.array()
});
expect(data.languages).to.contain(language);
setImmediate(callback);
});
};
});

@@ -1,12 +0,15 @@

module.exports = function () {
'use strict';
this.Given(/^I am on the "([^/"]*)\/([^"]*)" repository on GitHub$/, function (owner, repo, callback) {
callback(null, {
owner: owner,
repo: repo,
api: 'https://api.github.com',
token: process.env.ACCESS_TOKEN
const { defineSupportCode } = require('cucumber');
defineSupportCode(({ Given }) => {
Given(/^I am on the "([^/"]*)\/([^"]*)" repository on GitHub$/, function (owner, repo) {
const world = this;
world.setAttributes({
owner,
repo,
api: 'https://api.github.com'
});
});
};
});

@@ -1,5 +0,5 @@

var hoek = require('hoek'),
joi = require('joi'),
request = require('request');
'use strict';
const joi = require('joi');
/**

@@ -10,11 +10,11 @@ * Set a dot-deliminated value in an object

* @param {Object} object Object to manipulate
* @param {String} key Dot-deliminated key
* @param {String} search Dot-deliminated key
* @param {Varied} value Value to set to
*/
function setValue(object, key, value) {
var keys = key.split('.'),
last = keys.length - 1,
ref = object;
function setValue(object, search, value) {
const keys = search.split('.');
const last = keys.length - 1;
let ref = object;
keys.forEach(function (key, index) {
keys.forEach((key, index) => {
if (index === last) {

@@ -25,3 +25,3 @@ ref[key] = value;

} else if (typeof ref[key] !== 'object') {
throw new Error('Unable to set a non-object ' + key + ': ' + typeof ref[key]);
throw new Error(`Unable to set a non-object ${key}: ${typeof ref[key]}`);
}

@@ -32,110 +32,53 @@ ref = ref[key];

module.exports = function () {
this.World = function (callback) {
callback(Object.freeze({
/**
* Internal values saved by the steps
* @internal
* @type {Object}
*/
_values: {},
module.exports = function ({ attach, parameters }) {
const world = this;
/**
* Default values in all requests
* @internal
* @type {Object}
*/
_defaults: {},
// Load defaults
world.attach = attach;
world.parameters = parameters;
/**
* Set a default key to the request object
* @method default
* @param {String} key Dot-deliminated key
* @param {Varied} value Value to set to
*/
default: function (key, value) {
setValue(this._defaults, key, value);
},
/**
* Internal attributes saved by the steps
* @internal
* @type {Object}
*/
world._attributes = {};
/**
* Store some value to be used in a later step
* @method store
* @param {String} key Dot-deliminated key
* @param {Varied} value Value to store to
*/
store: function (key, value) {
if (typeof key === 'object') {
Object.keys(key).forEach(function (k) {
setValue(this._values, k, key[k]);
}.bind(this));
} else {
setValue(this._values, key, value);
}
},
/**
* Validate and retrieve the values this step needs
* @method retrieve
* @param {Object} schema Joi validation schema
* @return {Object} Values you were validating
*/
retrieve: function (schema) {
var result = joi.validate(this._values, schema, {
allowUnknown: true,
presence: 'required'
});
if (result.error) {
throw new Error(result.error.annotate());
}
return result.value;
},
/**
* Make an API call
* @method request
* @param {Object} options Request options
* @param {Function} callback Function to run when done (err, request, response)
*/
request: function (options, callback) {
request(hoek.applyToDefaults(this._defaults, options), callback.bind(this));
}
}));
/**
* Store some value to be used in a later step
* @method setAttributes
* @param {String} key Dot-deliminated key
* @param {Varied} value Value to store to
*/
world.setAttributes = (key, value) => {
if (typeof key === 'object') {
Object.keys(key).forEach((k) => {
setValue(world._attributes, k, key[k]);
});
} else {
setValue(world._attributes, key, value);
}
};
world.setAttribute = world.setAttributes;
/**
* Define a step with requirements
* @defineStepWithRequirements
* @param {String} regex Regex to match
* @param {Object} [requirements] Joi object requirements
* @param {Function} callback Function to run when done ([requirements], [args..], callback)
* Validate and retrieve the attributes this step needs
* @method getAttributes
* @param {Object} schema Joi validation schema
* @return {Object} Values you were validating
*/
this.defineStepWithRequirements = function (regex, requirements, callback) {
// requirements is not required
if (!callback) {
callback = requirements;
requirements = null;
world.getAttributes = (schema) => {
const result = joi.validate(world._attributes, schema, {
allowUnknown: true,
presence: 'required'
});
if (result.error) {
throw new Error(result.error.details.map(detail => detail.message).join('\n'));
}
this.defineStep(regex, function () {
var args = Array.prototype.slice.call(arguments),
next = args.pop();
if (requirements) {
args = [this.retrieve(requirements)].concat(args);
}
args.push(function (err, data) {
this.store(data || {});
next(err);
}.bind(this));
callback.apply(this, args);
});
return result.value;
};
this.When = this.defineStepWithRequirements;
this.Given = this.defineStepWithRequirements;
this.Then = this.defineStepWithRequirements;
this.joi = joi;
world.joi = joi;
};
{
"name": "cucumber-enhancement",
"version": "1.0.0",
"version": "3.0.0",
"description": "Enhances cucumber.js to make it easier to interact between steps",
"main": "index.js",
"scripts": {
"test": "jenkins-mocha tests/**",
"functional": "cucumber.js --require lib/* --require features/"
"pretest": "eslint .",
"test": "jenkins-mocha",
"posttest": "cucumber.js"
},

@@ -21,2 +22,5 @@ "repository": {

"license": "MIT",
"engines": {
"node": ">= 6"
},
"bugs": {

@@ -27,13 +31,13 @@ "url": "https://github.com/stjohnjohnson/cucumber-enhancement/issues"

"dependencies": {
"hoek": "^2.11.0",
"joi": "^5.1.0",
"request": "^2.51.0"
"hoek": "^5.0.2",
"joi": "^13.0.2"
},
"devDependencies": {
"cucumber": "^0.4.7",
"chai": "^1.10.0",
"jenkins-mocha": "^1.0.9",
"mockery": "^1.4.0",
"sinon": "^1.12.2"
"chai": "^4.1.2",
"cucumber": "^3.1.0",
"eslint": "^4.11.0",
"eslint-config-screwdriver": "^3.0.0",
"jenkins-mocha": "^6.0.0",
"request": "^2.83.0"
}
}

@@ -1,2 +0,2 @@

# cucumberjs-enhancement
# cucumber-enhancement

@@ -7,18 +7,20 @@ Enhances cucumber.js to make it easier to interact between steps.

* Create a file `features/support/enhancement-hook.js` as follows
* Create a file `features/step_definitions/world-enhance.js` as follows
```
module.exports = require('cucumber-enhancement');
const {setWorldConstructor} = require('cucumber');
setWorldConstructor(require('cucumber-enhancement'));
```
This does the following:
This modifies the World object to do the following:
* Adds an additional argument to the step callback that saves the values for use in other steps:
* Write attributes for later retrieval:
```javascript
this.Given(/^I am on the "([^/"]*)\/([^"]*)" repository on GitHub$/, function (owner, repo, callback) {
Given(/^I am on the "([^/"]*)\/([^"]*)" repository on GitHub$/, function (owner, repo) {
// This saves owner and repo for use in other steps
callback(null, {
owner: owner,
repo: repo
this.setAttributes({
owner,
repo
});

@@ -28,12 +30,12 @@ });

* Adds a new optional argument to `when`, `then`, and `given` to require data saved from other steps:
* Read attributes from previous steps:
```javascript
this.Then(/^I should see "([^"]*)" as one of the branches$/, {
branches: this.joi.array()
}, function (data, branch, callback) {
Then(/^I should see "([^"]*)" as one of the branches$/, function (branch) {
const data = this.getAttributes({
branches: this.joi.array()
});
// data.branches contains data saved from another step
expect(data.branches).to.contain(branch);
setImmediate(callback);
});

@@ -43,25 +45,1 @@ ```

* Exposes [`joi`](https://www.npmjs.com/package/joi) interface for quick access during step definition (see above).
* Bakes [`request`](https://www.npmjs.com/package/request) module into the world for easy access and automatically sets the scope of the callback function:
```javascript
this.request({
method: 'GET',
uri: 'http://foo.yahoo.com/'
}, function (err, message, response) {
callback(null, {
'bar': Object.keys(response)
});
});
```
* Allows you to default values for the request module (mostly used by cucumber @tags):
```javascript
this.Before("@github_api", function(callback) {
this.default('headers.User-Agent', 'Cucumber Test');
this.default('json', true);
setImmediate(callback);
});
```
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