cucumber-fp
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "cucumber-fp", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Cucumber.js with functional programming-style step definitions", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"author": "Julien Biezemans <jb@jbpros.com>", | ||
"homepage": "https://github.com/jbpros/cucumber-fp", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jbpros/cucumber-fp.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jbpros/cucumber-fp/issues" | ||
}, | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"files": [ | ||
"lib/" | ||
], | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"license": "MIT", | ||
@@ -38,6 +56,3 @@ "devDependencies": { | ||
"test": "cucumber-js" | ||
}, | ||
"files": [ | ||
"lib/" | ||
] | ||
} | ||
} |
@@ -5,3 +5,3 @@ # Cucumber.js FP step definitions | ||
This little library brings functional programming style step definitions to Cucumber.js. | ||
This little library brings functional programming style step definitions to Cucumber.js. We highly recommend using it with TypeScript as it enforces read-only constraints on the context and all its nested members in your functional step definitions. | ||
@@ -49,2 +49,25 @@ ## Install | ||
### Mutations of context are forbidden | ||
```typescript | ||
import { withContext } from 'cucumber-fp' | ||
interface MyContext { a: string[] } | ||
const initialContext: MyContext = { a: ['a', 'b'] } | ||
const { When } = withContext(initialContext) | ||
When('a step', (ctx) => { | ||
ctx.a.push('c') | ||
// ^--- TypeScript compiler will fail here, | ||
// `ctx` is deeply read-only. The following | ||
// would work instead: | ||
ctx = { ...ctx, a: [...ctx.a, 'c']} | ||
return ctx | ||
}) | ||
``` | ||
The type of `ctx` passed to your step definitions is always [`DeepReadonly<C>`](https://github.com/krzkaczor/ts-essentials#Deep-wrapper-types) (where `C` is the type of your context, in the example above, `MyContext`). That means all mutation operations are forbidden. | ||
Theses constraints have no effects if you're not writing your step definitions in TypeScript, which we highly recommend. | ||
### Steps that don't change context | ||
@@ -51,0 +74,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
12240
0
1
84
0