Skip to content

Commit

Permalink
docs(extensions): improve extensions installation documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Jun 29, 2017
1 parent 3b0b88a commit 5f5ea08
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 4 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
}
],
"license": "MIT",
"engines": {
"node" : ">=6.0.0"
},
"engineStrict": true,
"dependencies": {
"chai": "^4.0.2",
"lodash": "^4.17.4"
Expand Down
19 changes: 15 additions & 4 deletions src/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ const _ = require('lodash')
* - date
* - string
*
* @example
* Cast.value('2((number))')
* Cast.value('true((boolean))')
* Cast.value('((null))')
* Cast.value('raw')
* // output
* // > 2
* // > true
* // > null
* // > 'raw'
*
* @param {string} value - The value to cast
* @return {*} The casted value or untouched value if no casting directive found
*/
Expand Down Expand Up @@ -94,10 +105,10 @@ exports.object = object => {
* { username: 'john((string))', is_active: 'false((boolean))', age: '32((number))' },
* ])
* // output
* [
* { username: 'plouc', is_active: true, age: 25 },
* { username: 'john', is_active: false, age: 32 },
* ]
* // > [
* // > { username: 'plouc', is_active: true, age: 25 },
* // > { username: 'john', is_active: false, age: 32 },
* // > ]
*
* @param {Array.<Object>} objects
*/
Expand Down
34 changes: 34 additions & 0 deletions src/extensions/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,45 @@ const hooks = require('./hooks')
/**
* Extends cucumber world object.
* Must be used inside customWorldConstructor.
*
* @example
* // /support/world.js
*
* const { defineSupportCode } = require('cucumber')
* const { state, cli } = require('@ekino/veggies')
*
* defineSupportCode(({ setWorldConstructor }) => {
* setWorldConstructor(function() {
* state.extendWorld(this) // cli extension requires state extension
* cli.extendWorld(this)
* })
* })
*
* @function
* @param {Object} world - The cucumber world object
*/
exports.extendWorld = require('./extend_world')

/**
* Installs the extension.
*
* @example
* // /support/world.js
*
* const { defineSupportCode } = require('cucumber')
* const { state, cli } = require('@ekino/veggies')
*
* defineSupportCode(({ setWorldConstructor }) => {
* setWorldConstructor(function() {
* state.extendWorld(this) // cli extension requires state extension
* cli.extendWorld(this)
* })
* })
*
* state.install(defineSupportCode)
* cli.install(defineSupportCode)
*
* @param {Function} define - The `defineSupportCode` helper from cucumber
*/
exports.install = define => {
define(definitions)
Expand Down
44 changes: 44 additions & 0 deletions src/extensions/http_api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,55 @@ const hooks = require('./hooks')
/**
* Extends cucumber world object.
* Must be used inside customWorldConstructor.
*
* @example
* // /support/world.js
*
* const { defineSupportCode } = require('cucumber')
* const { state, httpApi } = require('@ekino/veggies')
*
* defineSupportCode(({ setWorldConstructor }) => {
* setWorldConstructor(function() {
* state.extendWorld(this) // httpApi extension requires state extension
* httpApi.extendWorld(this)
* })
* })
*
* @function
* @param {Object} world - The cucumber world object
*/
exports.extendWorld = require('./extend_world')

/**
* The http API configuration object.
*
* @typedef {Object} HttpApiConfig
* @property {string} [baseUrl=''] - The base url used for all http calls
*/

/**
* Installs the extension.
*
* @example
* // /support/world.js
*
* const { defineSupportCode } = require('cucumber')
* const { state, httpApi } = require('@ekino/veggies')
*
* defineSupportCode(({ setWorldConstructor }) => {
* setWorldConstructor(function() {
* state.extendWorld(this) // httpApi extension requires state extension
* httpApi.extendWorld(this)
* })
* })
*
* state.install(defineSupportCode)
* httpApi.install({
* baseUrl: 'http://localhost:3000',
* })(defineSupportCode)
*
* @param {HttpApiConfig} config - The `defineSupportCode` helper from cucumber
* @return {Function} The installation function
*/
exports.install = ({ baseUrl = '' } = {}) => define => {
define(definitions({ baseUrl }))
Expand Down
31 changes: 31 additions & 0 deletions src/extensions/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,42 @@ const definitions = require('./definitions')
/**
* Extends cucumber world object.
* Must be used inside customWorldConstructor.
*
* @example
* // /support/world.js
*
* const { defineSupportCode } = require('cucumber')
* const { state } = require('@ekino/veggies')
*
* defineSupportCode(({ setWorldConstructor }) => {
* setWorldConstructor(function() {
* state.extendWorld(this)
* })
* })
*
* @function
* @param {Object} world - The cucumber world object
*/
exports.extendWorld = require('./extend_world')

/**
* Installs the extension.
*
* @example
* // /support/world.js
*
* const { defineSupportCode } = require('cucumber')
* const { state } = require('@ekino/veggies')
*
* defineSupportCode(({ setWorldConstructor }) => {
* setWorldConstructor(function() {
* state.extendWorld(this)
* })
* })
*
* state.install(defineSupportCode)
*
* @param {Function} define - The `defineSupportCode` helper from cucumber
*/
exports.install = define => {
define(definitions)
Expand Down

0 comments on commit 5f5ea08

Please sign in to comment.