Skip to content

Commit

Permalink
feat(cli): init CLI extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Jun 29, 2017
1 parent 843d072 commit 42430f2
Show file tree
Hide file tree
Showing 13 changed files with 424 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/coverage/*
/coverage/*
/doc/*
96 changes: 93 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
[![Coverage Status][coverage-image]][coverage-url]
[![styled with prettier][prettier-image]][prettier-url]

Veggies is an awesome cucumberjs boilerplate for API testing.
Veggies is an awesome cucumberjs boilerplate for API/CLI testing.
Great for testing APIs built upon Express, Koa, HAPI, Loopback and others.
It's also the perfect companion for testing CLI applications built with commander, meow & Co.

- [Installation](#installation)
- [Features](#features)
Expand All @@ -15,9 +16,11 @@ Great for testing APIs built upon Express, Koa, HAPI, Loopback and others.
- [Posting data](#posting-data)
- [Using values issued by a previous request](#using-values-issued-by-a-previous-request)
- [Type system](#type-system)
- [CLI testing](#cli-testing)
- [Extensions](#extensions)
- [state](#state-extension)
- [http API](#http-api-extension)
- [CLI](#cli-extension)
- [Examples](#examples)

## Installation
Expand All @@ -40,20 +43,21 @@ Then all you have to do is installing the provided extensions:
// /support/world.js

const { defineSupportCode } = require('cucumber')
const { state, httpApi } = require('@ekino/veggies')
const { state, httpApi, cli } = require('@ekino/veggies')

defineSupportCode(({ setWorldConstructor }) => {
setWorldConstructor(function() {
state.extendWorld(this)
httpApi.extendWorld(this)
cli.extendWorld(this)
})
})

state.install(defineSupportCode)
httpApi.install({
baseUrl: 'http://localhost:3000',
})(defineSupportCode)

cli.install(defineSupportCode)
```

## Features
Expand Down Expand Up @@ -191,6 +195,11 @@ which will generate the following payload:
}
```

### CLI testing

For an exhaustive list of all available step definitions you should have a look
at the [definitions file](https://github.com/ekino/veggies/blob/master/src/extensions/cli/definitions.js).

## Extensions

This module is composed of several extensions.
Expand All @@ -203,6 +212,23 @@ The state extension is a simple helper used to persist state between steps & eve
It's involved for example when [you want to collect values issued by a previous request](#using-values-issued-by-a-previous-request)
when using the [http API extension](#http-api-extension).

To install the extension, you should add the following snippet to your `world` file:

```javascript
// /support/world.js

const { defineSupportCode } = require('cucumber')
const { state } = require('@ekino/veggies')

defineSupportCode(({ setWorldConstructor }) => {
setWorldConstructor(function() {
state.extendWorld(this)
})
})

state.install(defineSupportCode)
```

When installed, you can access it from the global cucumber context in your own step definitions.
For available methods on the state, please refer to its own
[documentation](https://ekino.github.io/veggies/module-extensions_state_State.html).
Expand All @@ -221,6 +247,27 @@ defineSupportCode(({ When }) => {
The http API extension relies on the [state extension](#state-extension),
so make sure it's registered prior to installation.

To install the extension, you should add the following snippet to your `world` file:

```javascript
// /support/world.js

const { defineSupportCode } = require('cucumber')
const { state, httpApi } = require('@ekino/veggies')

defineSupportCode(({ setWorldConstructor }) => {
setWorldConstructor(function() {
state.extendWorld(this)
httpApi.extendWorld(this)
})
})

state.install(defineSupportCode)
httpApi.install({
baseUrl: 'http://localhost:3000',
})(defineSupportCode)
```

When installed, you can access its client from the global cucumber context in your own step definitions.
For available methods on the client, please refer to its own
[documentation](https://ekino.github.io/veggies/module-extensions_httpApi_client.html).
Expand All @@ -233,6 +280,43 @@ defineSupportCode(({ When }) => {
})
```

### CLI extension

The CLI extension relies on the [state extension](#state-extension),
so make sure it's registered prior to installation.

To install the extension, you should add the following snippet to your `world` file:

```javascript
// /support/world.js

const { defineSupportCode } = require('cucumber')
const { state, cli } = require('@ekino/veggies')

defineSupportCode(({ setWorldConstructor }) => {
setWorldConstructor(function() {
state.extendWorld(this)
cli.extendWorld(this)
})
})

state.install(defineSupportCode)
cli.install(defineSupportCode)
```

When installed, you can access it from the global cucumber context in your own step definitions.
For available methods on the client, please refer to its own
[documentation](https://ekino.github.io/veggies/module-extensions_httpApi_client.html).

```javascript
defineSupportCode(({ When }) => {
Then(/^I check something from the CLI output$/, function() {
const out = this.cli.getOutput()
//
})
})
```

## Examples

This repository comes with few examples, in order to run them, invoke the following script:
Expand All @@ -241,6 +325,12 @@ This repository comes with few examples, in order to run them, invoke the follow
yarn run examples
```

If you want to only run certain examples, you can use tags, for example to run cli extension examples:

```sh
yarn run examples -- --tags @cli
```

[npm-image]: https://img.shields.io/npm/v/@ekino/veggies.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@ekino/veggies
[travis-image]: https://img.shields.io/travis/ekino/veggies.svg?style=flat-square
Expand Down
12 changes: 12 additions & 0 deletions examples/features/cli/yarn.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@cli
Feature: yarn CLI

Scenario: Running an invalid command
When I run command yarn invalid
Then exit code should be 1
And stderr should contain error Command "invalid" not found.

Scenario: Getting yarn version
When I run command yarn --version
Then exit code should be 0
And stdout should match ^[0-9]{1}.[0-9]{1,3}.[0-9]{1,3}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@http_api
Feature: GitHub API

Scenario: Using GitHub API
Expand Down
4 changes: 3 additions & 1 deletion examples/support/world.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict'

const { defineSupportCode } = require('cucumber')
const { state, httpApi } = require('../../src')
const { state, httpApi, cli } = require('../../src')

defineSupportCode(({ setWorldConstructor }) => {
setWorldConstructor(function() {
state.extendWorld(this)
httpApi.extendWorld(this)
cli.extendWorld(this)
})
})

state.install(defineSupportCode)
httpApi.install({})(defineSupportCode)
cli.install(defineSupportCode)
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "veggies",
"version": "0.1.0",
"description": "Veggies is an awesome cucumber-js boilerplate for API/CLI testing. Great for Express, HAPI, Loopback, and others. Unbelievable greatness for life improvement.",
"description": "Veggies is an awesome cucumberjs boilerplate for API/CLI testing. Great for testing APIs built upon Express, Koa, HAPI, Loopback and others. It's also the perfect companion for testing CLI applications built with commander, meow & Co.",
"tags": [
"bdd",
"cucumber",
"gherkin",
"testing",
"api"
"api",
"cli"
],
"repository": {
"type": "git",
Expand Down

0 comments on commit 42430f2

Please sign in to comment.