1
0
This commit is contained in:
Eugen Wissner 2018-11-10 20:06:38 +01:00
parent 5d535973f3
commit 15e5e413d9
42 changed files with 11638 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

7
1args/babel.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
presets: [
[ '@babel/env', {
useBuiltIns: 'usage'
}]
]
}

View File

@ -0,0 +1,9 @@
Feature: Add Numbers
As a user of the calculator
I want to add 2 numbers
Scenario: Add numbers
Given the start value is 5
When I add 6
Then the result should be 11

View File

@ -0,0 +1,7 @@
Feature: Concatenate strings
As a user of the concatenator
I want to concatenate 2 strings
Scenario: Concatenate strings
When I concatenate "Georg" and "Cantor"
Then the result should be "Georg Cantor"

View File

@ -0,0 +1,12 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the start value is {int}', function (int) {
})
When('I add {int}', function (int) {
})
Then('the result should be {int}', function (int) {
expect(int).to.equal(11)
})

View File

@ -0,0 +1,9 @@
import { When, Then } from 'cucumber'
import { expect } from 'chai'
When('I concatenate {string} and {string}', function (string, string2) {
})
Then('the result should be {string}', function (string) {
expect(string).to.equal("Georg Cantor")
})

1764
1args/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
1args/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "1args",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cucumber-js --require-module '@babel/register'"
},
"author": "Eugen Wissner <belka@caraus.de>",
"license": "MPL-2.0",
"dependencies": {
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.4",
"chai": "^4.2.0",
"cucumber": "^5.0.2"
}
}

7
2obj/babel.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
presets: [
[ '@babel/env', {
useBuiltIns: 'usage'
}]
]
}

View File

@ -0,0 +1,13 @@
Feature: Add Numbers
As a user of the calculator
I want to add 2 numbers
Scenario: Add numbers
Given the start value is 5
When I add 6
Then the result should be 11
Scenario: Add numbers
Given the start value is 5
When I add 25
Then the result should be 30

View File

@ -0,0 +1,15 @@
Feature: Concatenate strings
As a user of the concatenator
I want to concatenate 2 strings
Scenario: Concatenate strings
Given the start value is "Georg"
When I concatenate "Cantor"
Then the result should be "Georg Cantor"
Scenario: Concatenate strings
Given the start value is "Georg"
When I concatenate "Wilhelm"
When I concatenate "Friedrich"
When I concatenate "Hegel"
Then the result should be "Georg Wilhelm Friedrich Hegel"

View File

@ -0,0 +1,14 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the start value is {int}', function (int) {
this.calc = int
})
When('I add {int}', function (int) {
this.calc += int
})
Then('the result should be {int}', function (int) {
expect(this.calc).to.equal(int)
})

View File

@ -0,0 +1,14 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the start value is {string}', function (string) {
this.concat = string
})
When('I concatenate {string}', function (string) {
this.concat += ' ' + string
})
Then('the result should be {string}', function (string) {
expect(string).to.equal(this.concat)
})

1771
2obj/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
2obj/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "2obj",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cucumber-js --require-module '@babel/register'"
},
"author": "Eugen Wissner <belka@caraus.de>",
"license": "MPL-2.0",
"dependencies": {
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.4",
"chai": "^4.2.0",
"cucumber": "^5.0.2"
}
}

7
3bg/babel.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
presets: [
[ '@babel/env', {
useBuiltIns: 'usage'
}]
]
}

View File

@ -0,0 +1,14 @@
Feature: Add Numbers
As a user of the calculator
I want to add 2 numbers
Background:
Given the start value is 5
Scenario: Add numbers
When I add 6
Then the result should be 11
Scenario: Add numbers
When I add 25
Then the result should be 30

View File

@ -0,0 +1,16 @@
Feature: Concatenate strings
As a user of the concatenator
I want to concatenate 2 strings
Background:
Given the start value is "Georg"
Scenario: Concatenate strings
When I concatenate "Cantor"
Then the result should be "Georg Cantor"
Scenario: Concatenate strings
When I concatenate "Wilhelm"
When I concatenate "Friedrich"
When I concatenate "Hegel"
Then the result should be "Georg Wilhelm Friedrich Hegel"

View File

@ -0,0 +1,14 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the start value is {int}', function (int) {
this.calc = int
})
When('I add {int}', function (int) {
this.calc += int
})
Then('the result should be {int}', function (int) {
expect(this.calc).to.equal(int)
})

View File

@ -0,0 +1,14 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the start value is {string}', function (string) {
this.concat = string
})
When('I concatenate {string}', function (string) {
this.concat += ' ' + string
})
Then('the result should be {string}', function (string) {
expect(string).to.equal(this.concat)
})

1771
3bg/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
3bg/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "3bg",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cucumber-js --require-module '@babel/register'"
},
"author": "Eugen Wissner <belka@caraus.de>",
"license": "MPL-2.0",
"dependencies": {
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.4",
"chai": "^4.2.0",
"cucumber": "^5.0.2"
}
}

7
4outline/babel.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
presets: [
[ '@babel/env', {
useBuiltIns: 'usage'
}]
]
}

View File

@ -0,0 +1,15 @@
Feature: Add Numbers
As a user of the calculator
I want to add 2 numbers
Background:
Given the start value is 5
Scenario Outline: Add numbers
When I add <summand>
Then the result should be <sum>
Examples:
| summand | sum |
| 6 | 11 |
| 25 | 30 |

View File

@ -0,0 +1,16 @@
Feature: Concatenate strings
As a user of the concatenator
I want to concatenate 2 strings
Background:
Given the start value is "Georg"
Scenario: Concatenate strings
When I concatenate "Cantor"
Then the result should be "Georg Cantor"
Scenario: Concatenate strings
When I concatenate "Wilhelm"
When I concatenate "Friedrich"
When I concatenate "Hegel"
Then the result should be "Georg Wilhelm Friedrich Hegel"

View File

@ -0,0 +1,14 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the start value is {int}', function (int) {
this.calc = int
})
When('I add {int}', function (int) {
this.calc += int
})
Then('the result should be {int}', function (int) {
expect(this.calc).to.equal(int)
})

View File

@ -0,0 +1,14 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the start value is {string}', function (string) {
this.concat = string
})
When('I concatenate {string}', function (string) {
this.concat += ' ' + string
})
Then('the result should be {string}', function (string) {
expect(string).to.equal(this.concat)
})

1771
4outline/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
4outline/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "4outline",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cucumber-js --require-module '@babel/register'"
},
"author": "Eugen Wissner <belka@caraus.de>",
"license": "MPL-2.0",
"dependencies": {
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.4",
"chai": "^4.2.0",
"cucumber": "^5.0.2"
}
}

45
README.md Normal file
View File

@ -0,0 +1,45 @@
# Cucumber.js examples
This repository demonstrates features of Cucumber.js. Each directory contains
an independent npm-package with an example.
The packages have standard directory structure:
- Features are in the `feature/` directory and have `.feature` extension.
- Step definitions are JavaScript files in `feature/steps/`.
## Running the tests
1. Go to a directory
2. Install npm dependencies:
```sh
npm install
```
3. Run the tests:
```sh
npm test
```
## Available examples
### 1-5
The directories with the names starting with a number are parts of a single
step-by-step guide which introduces Cucumber.js. Each step of this guide
builds on the previous one and contains a few more lines of JavaScript code.
The target project is a small test suite for the JavaScript `+` operator.
### data-tables
When data tables are used, Cucumber.js provides different views of the data.
This directory contains one feature with four scenarios, each of which uses a
different way to read the given table. These tests cover all possibilities to
access the data in a data table.
See [Data tables](https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/data_table_interface.md).
### async
Shows how to use promises and `async`/`await` when testing asynchronous code.

7
async/babel.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
presets: [
[ '@babel/env', {
useBuiltIns: 'usage'
}]
]
}

View File

@ -0,0 +1,8 @@
Feature: Request
Scenario:
When I request the same resource three times
Then the responses should be the same
Scenario:
When I request the same resource twice
Then the responses should be the same

View File

@ -0,0 +1,9 @@
import { When } from 'cucumber'
import axios from 'axios'
When('I request the same resource twice', async function () {
const url = 'http://localhost:8080/'
this.first = await axios.request(url).data
this.second = await axios.request(url).data
})

View File

@ -0,0 +1,25 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
import axios from 'axios'
When('I request the same resource three times', function () {
const url = 'http://localhost:8080/'
return axios.request(url)
.then(res => {
this.first = res.data
return axios.request(url)
}).then(res => {
this.second = res.data
return axios.request(url)
}).then(res => {
this.third = res.data
})
})
Then('the responses should be the same', function () {
expect(this.first).to.equal(this.second)
expect(this.second).to.equal(this.third)
})

View File

@ -0,0 +1,20 @@
import { BeforeAll, AfterAll } from 'cucumber'
import express from 'express'
let server
BeforeAll(function () {
const app = express()
app.get('/', (req, res) => {
res.send('Alea iacta est')
})
server = app.listen(8080)
})
AfterAll(function () {
server.close()
})

2195
async/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

21
async/package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "async",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cucumber-js --require-module '@babel/register'"
},
"author": "Eugen Wissner <belka@caraus.de>",
"license": "MPL-2.0",
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"axios": "^0.18.0",
"babel-loader": "^8.0.4",
"chai": "^4.2.0",
"cucumber": "^5.0.2",
"express": "^4.16.4"
}
}

View File

@ -0,0 +1,7 @@
module.exports = {
presets: [
[ '@babel/env', {
useBuiltIns: 'usage'
}]
]
}

View File

@ -0,0 +1,69 @@
Feature:
As the owner of a book collection
I want to be able to generate JSON containing titles from this collection
Scenario:
Given the following books by Simon Frank are in the collection:
| id | title |
| 1 | Der Gegenstand des Wissens |
| 2 | Lebendiges Wissen |
When I stringify it
Then I should get:
"""
[{
"id": 1,
"title": "Der Gegenstand des Wissens"
},{
"id": 2,
"title": "Lebendiges Wissen"
}]
"""
Given the following books by Søren Kierkegaard are in the collection:
| id | title |
| 1 | Die Krankheit zum Tode |
| 2 | Entweder-Oder |
When I stringify it
Then I should get:
"""
[{
"id": 1,
"title": "Die Krankheit zum Tode"
},{
"id": 2,
"title": "Entweder-Oder"
}]
"""
Given the following book is in the collection:
| id | 1 |
| title | Leonce und Lena |
| author | Georg Büchner |
When I stringify it
Then I should get:
"""
{
"id": 1,
"title": "Leonce und Lena",
"author": "Georg Büchner"
}
"""
Given the following books are in the collection:
| Friedrich Nietzsche | Die Geburt der Tragödie |
| Jacques Derrida | Die unbedingte Universität |
| Honoré de Balzac | Die Frau von 30 Jahren |
When I stringify it
Then I should get:
"""
[{
"author": "Friedrich Nietzsche",
"title": "Die Geburt der Tragödie"
},{
"author": "Jacques Derrida",
"title": "Die unbedingte Universität"
},{
"author": "Honoré de Balzac",
"title": "Die Frau von 30 Jahren"
}]
"""

View File

@ -0,0 +1,50 @@
import { Given, When, Then } from 'cucumber'
import { expect } from 'chai'
Given('the following books by Simon Frank are in the collection:', function (dataTable) {
this.objects = []
dataTable.hashes().forEach(el => {
this.objects.push({
id: parseInt(el.id),
title: el.title
})
})
})
Given('the following books by Søren Kierkegaard are in the collection:', function (dataTable) {
this.objects = []
dataTable.rows().forEach(el => {
this.objects.push({
id: parseInt(el[0]),
title: el[1]
})
})
})
Given('the following book is in the collection:', function (dataTable) {
const data = dataTable.rowsHash()
this.objects = {
id: parseInt(data.id),
title: data.title,
author: data.author
}
})
Given('the following books are in the collection:', function (dataTable) {
this.objects = []
dataTable.raw().forEach(el => {
this.objects.push({
author: el[0],
title: el[1]
})
})
})
When('I stringify it', function () {
this.result = JSON.stringify(this.objects)
})
Then('I should get:', function (expected) {
expect(JSON.parse(expected))
.to.deep.equal(JSON.parse(this.result))
})

1771
data-tables/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
data-tables/package.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "data-tables",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "cucumber-js --require-module '@babel/register'"
},
"author": "Eugen Wissner <belka@caraus.de>",
"license": "MPL-2.0",
"dependencies": {
"@babel/core": "^7.1.5",
"@babel/preset-env": "^7.1.5",
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.4",
"chai": "^4.2.0",
"cucumber": "^5.0.2"
}
}