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

cucumber-expressions

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cucumber-expressions - npm Package Compare versions

Comparing version 4.0.4 to 5.0.0

dist/src/argument.js

13

package.json
{
"name": "cucumber-expressions",
"version": "4.0.4",
"version": "5.0.0",
"description": "Cucumber Expressions - a simpler alternative to Regular Expressions",
"main": "dist/index.js",
"main": "dist/src/index.js",
"scripts": {
"test": "npm run eslint && npm run coverage",
"eslint": "eslint src test",
"build": "babel src --out-dir dist",
"prepublish": "npm run build",
"build": "babel src --out-dir dist/src",
"build-test": "babel test --out-dir dist/test",
"prepare": "yarn build",
"postinstall": "node scripts/postinstall.js",
"mocha": "mocha",
"mocha-built": "mocha dist/test",
"coverage": "nyc --reporter=html --reporter=text mocha",

@@ -34,3 +36,4 @@ "precommit": "lint-staged"

"babel-cli": "^6.23.0",
"babel-preset-es2015": "^6.22.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"eslint": "^4.0.0",

@@ -37,0 +40,0 @@ "eslint-config-eslint": "^4.0.0",

@@ -5,9 +5,7 @@ var path = require('path')

fs.exists(path.join(__dirname, '..', 'dist'), function(distExists, err) {
if (err) throw err
if (!distExists) {
exec('npm run build', { cwd: path.join(__dirname, '..') }, function(err) {
if (err) throw err
})
}
fs.access(path.join(__dirname, '..', 'dist'), function(err) {
if (!err) return
exec('yarn build', { cwd: path.join(__dirname, '..') }, function(err) {
if (err) throw err
})
})

@@ -34,6 +34,10 @@ const { CucumberExpressionError } = require('./errors')

get value() {
return this._parameterType.transform(
this._group ? this._group.values : null
)
/**
* Get the value returned by the parameter type's transformer function.
*
* @param thisObj the object in which the transformer function is applied.
*/
getValue(thisObj) {
let groupValues = this._group ? this._group.values : null
return this._parameterType.transform(thisObj, groupValues)
}

@@ -40,0 +44,0 @@ }

@@ -57,3 +57,4 @@ const { CucumberExpressionError } = require('./errors')

transform(groupValues) {
transform(thisObj, groupValues) {
let args
if (this._transform.length === 1) {

@@ -68,6 +69,8 @@ // transform function with arity 1.

)
return this._transform(nonNullGroupValues[0])
args = [nonNullGroupValues[0]]
} else {
args = groupValues
}
return this._transform.apply(null, groupValues)
return this._transform.apply(thisObj, args)
}

@@ -74,0 +77,0 @@ }

/* eslint-env mocha */
const assert = require('assert')
const { CucumberExpression, ParameterTypeRegistry } = require('../src/index')
const {
CucumberExpression,
ParameterTypeRegistry,
ParameterType,
} = require('../src/index')

@@ -13,3 +17,3 @@ describe('CucumberExpression', () => {

const args = expression.match('I have 7 cukes')
assert.equal(7, args[0].value)
assert.equal(7, args[0].getValue(null))
/// [capture-match-arguments]

@@ -92,2 +96,31 @@ })

it('delegates transform to custom object', () => {
const parameterTypeRegistry = new ParameterTypeRegistry()
parameterTypeRegistry.defineParameterType(
new ParameterType(
'widget',
/\w+/,
null,
function(s) {
return this.createWidget(s)
},
false,
true
)
)
const expression = new CucumberExpression(
'I have a {widget}',
parameterTypeRegistry
)
const world = {
createWidget(s) {
return `widget:${s}`
},
}
const args = expression.match(`I have a bolt`)
assert.equal(args[0].getValue(world), 'widget:bolt')
})
describe('escapes special characters', () => {

@@ -102,3 +135,3 @@ ;['\\', '[', ']', '^', '$', '.', '|', '?', '*', '+'].forEach(character => {

const arg1 = expression.match(`I have 800 cukes and ${character}`)[0]
assert.equal(arg1.value, 800)
assert.equal(arg1.getValue(null), 800)
})

@@ -115,3 +148,3 @@ })

const arg1 = expression.match(`I have 800 cukes and .`)[0]
assert.equal(arg1.value, 800)
assert.equal(arg1.getValue(null), 800)
})

@@ -128,3 +161,3 @@

const arg1 = expression.match(`I have 800 cukes and a|b`)[0]
assert.equal(arg1.value, 800)
assert.equal(arg1.getValue(null), 800)
})

@@ -141,3 +174,3 @@ })

if (!args) return null
return args.map(arg => arg.value)
return args.map(arg => arg.getValue(null))
}

@@ -10,2 +10,3 @@ /* eslint-env mocha */

const ParameterType = require('../src/parameter_type')
require('babel-polyfill')

@@ -38,3 +39,3 @@ class Color {

Color, // type
s => new Color(s), // transform
s => new Color(s), // transformer
false, // useForSnippets

@@ -54,3 +55,3 @@ true // preferForRegexpMatch

)
const value = expression.match('I have a red ball')[0].value
const value = expression.match('I have a red ball')[0].getValue(null)
assert.equal(value.name, 'red')

@@ -84,6 +85,6 @@ })

const thick = args[0].value
const thick = args[0].getValue(null)
assert.equal(thick, 5)
const from = args[1].value
const from = args[1].getValue(null)
assert.equal(from.x, 10)

@@ -93,3 +94,3 @@ assert.equal(from.y, 20)

const to = args[2].value
const to = args[2].getValue(null)
assert.equal(to.x, 40)

@@ -116,3 +117,3 @@ assert.equal(to.y, 50)

)
const value = expression.match('I have a dark red ball')[0].value
const value = expression.match('I have a dark red ball')[0].getValue(null)
assert.equal(value.name, 'dark red')

@@ -140,3 +141,3 @@ })

const args = expression.match('I have a bad parameter')
assertThrows(() => args[0].value, "Can't transform [bad]")
assertThrows(() => args[0].getValue(null), "Can't transform [bad]")
})

@@ -191,3 +192,5 @@

parameterTypeRegistry
).match('I have a blue ball')[0].value.constructor,
)
.match('I have a blue ball')[0]
.getValue(null).constructor,
CssColor

@@ -199,17 +202,17 @@ )

parameterTypeRegistry
).match('I have a blue ball')[0].value.name,
)
.match('I have a blue ball')[0]
.getValue(null).name,
'blue'
)
assert.equal(
new CucumberExpression(
'I have a {color} ball',
parameterTypeRegistry
).match('I have a blue ball')[0].value.constructor,
new CucumberExpression('I have a {color} ball', parameterTypeRegistry)
.match('I have a blue ball')[0]
.getValue(null).constructor,
Color
)
assert.equal(
new CucumberExpression(
'I have a {color} ball',
parameterTypeRegistry
).match('I have a blue ball')[0].value.name,
new CucumberExpression('I have a {color} ball', parameterTypeRegistry)
.match('I have a blue ball')[0]
.getValue(null).name,
'blue'

@@ -241,3 +244,3 @@ )

const args = await expression.match('I have a red ball')
const value = await args[0].value
const value = await args[0].getValue(null)
assert.equal(value.name, 'red')

@@ -253,3 +256,3 @@ })

)
const value = expression.match('I have a red ball')[0].value
const value = expression.match('I have a red ball')[0].getValue(null)
assert.equal(value.constructor, Color)

@@ -256,0 +259,0 @@ assert.equal(value.name, 'red')

@@ -16,3 +16,3 @@ /* eslint-env mocha */

if (!args) return null
return args.map(arg => arg.value)
return args.map(arg => arg.getValue(null))
}

@@ -19,0 +19,0 @@

@@ -14,4 +14,4 @@ /* eslint-env mocha */

const args = expression.match('I have 7 cukes in my belly now')
assert.equal(7, args[0].value)
assert.equal('belly', args[1].value)
assert.equal(7, args[0].getValue(null))
assert.equal('belly', args[1].getValue(null))
/// [capture-match-arguments]

@@ -71,3 +71,3 @@ })

if (!args) return null
return args.map(arg => arg.value)
return args.map(arg => arg.getValue(null))
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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