@g_package/jest-cucumber-fusion 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/.prettierignore +16 -0
  2. package/.prettierrc.json +0 -0
  3. package/LICENSE +201 -0
  4. package/README.md +165 -0
  5. package/codecov +0 -0
  6. package/codecov.SHA256SUM +1 -0
  7. package/codecov.SHA256SUM.sig +16 -0
  8. package/docs/AdditionalConfiguration.md +155 -0
  9. package/docs/GherkinTables.md +61 -0
  10. package/docs/Language.md +76 -0
  11. package/docs/ReusingStepDefinitions.md +110 -0
  12. package/docs/RunningTheExamples.md +16 -0
  13. package/docs/ScenarioOutlines.md +43 -0
  14. package/docs/StepDefinitionArguments.md +37 -0
  15. package/package.json +82 -0
  16. package/src/index.d.ts +25 -0
  17. package/src/index.js +404 -0
  18. package/test/specs/features/basic-scenarios.feature +28 -0
  19. package/test/specs/features/language.feature +41 -0
  20. package/test/specs/features/reuse-definition.feature +13 -0
  21. package/test/specs/features/scenario-outline2.feature +71 -0
  22. package/test/specs/features/scenario-outlines.feature +88 -0
  23. package/test/specs/features/step-definitions/basic-scenarios.steps.js +45 -0
  24. package/test/specs/features/step-definitions/language.steps.js +86 -0
  25. package/test/specs/features/step-definitions/reuse-code.js +17 -0
  26. package/test/specs/features/step-definitions/reuse-definition.steps.js +22 -0
  27. package/test/specs/features/step-definitions/scenario-outline2.steps.js +46 -0
  28. package/test/specs/features/step-definitions/scenario-outlines.steps.js +110 -0
  29. package/test/specs/features/step-definitions/using-dynamic-values.steps.js +70 -0
  30. package/test/specs/features/step-definitions/using-gherkin-tables.steps.js +42 -0
  31. package/test/specs/features/using-dynamic-values.feature +34 -0
  32. package/test/specs/features/using-gherkin-tables.feature +16 -0
  33. package/test/src/bank-account.js +17 -0
  34. package/test/src/online-sales.js +33 -0
  35. package/test/src/rocket.js +13 -0
  36. package/test/src/todo-list.js +20 -0
@@ -0,0 +1,76 @@
1
+ # Language
2
+
3
+ You can use different languages in jest-cucumber-fusion by adding a `# language:` header,
4
+ for example `# language: nl` for dutch.
5
+ If you don't set any header the default language will be English (`en`).
6
+
7
+ Ghenkin has translated over 70 [languages](https://cucumber.io/docs/gherkin/languages/).
8
+
9
+ An example of a feature file in the dutch (nl) language:
10
+
11
+ ```gherkin
12
+ # language: nl
13
+
14
+ Functionaliteit: Online verkopen
15
+
16
+ Scenario: t-shirt verkopen
17
+ Gegeven ik heb een t-shirt
18
+ Als ik een t-shirt wil verkopen
19
+ Dan ontvang ik €22
20
+ En ben ik blij
21
+ Maar heb ik geen t-shirts over
22
+ ```
23
+ Most modern IDE's (or plugin) will support this feature and autocomplete keywords when using with a language.
24
+
25
+ The step-file can be defined as normal like:
26
+
27
+ ```javascript
28
+ const { Before, Given, When, Then, Fusion, And, But } = require('../../../../src')
29
+
30
+ const { OnlineSales } = require('../../../src/online-sales')
31
+
32
+ let onlineSales
33
+ let salesPrice
34
+
35
+ Before(() => { onlineSales = new OnlineSales() })
36
+
37
+ Given(/^ik heb een t-shirt$/, item => {
38
+ onlineSales.listItem('Rick Astley t-shirt')
39
+ })
40
+
41
+ When(/^ik een t-shirt wil verkopen$/, item => {
42
+ salesPrice = onlineSales.sellItem('Rick Astley t-shirt')
43
+ })
44
+ ...
45
+ ```
46
+
47
+ Optionally you can also translate the keywords in your step-files like so:
48
+
49
+ ```javascript
50
+ import {
51
+ Before,
52
+ Given as Gegeven,
53
+ When as Wanneer,
54
+ Then as Dan,
55
+ Fusion,
56
+ And as En,
57
+ But as Maar
58
+ } from '../../../../src'
59
+
60
+ const { OnlineSales } = require('../../../src/online-sales')
61
+
62
+ let onlineSales
63
+ let salesPrice
64
+
65
+ Before(() => { onlineSales = new OnlineSales() })
66
+
67
+ Given(/^ik heb een t-shirt$/, item => {
68
+ onlineSales.listItem('Rick Astley t-shirt')
69
+ })
70
+
71
+ When(/^ik een t-shirt wil verkopen$/, item => {
72
+ salesPrice = onlineSales.sellItem('Rick Astley t-shirt')
73
+ })
74
+ ...
75
+ ```
76
+ This example used `import` which requires ES6.
@@ -0,0 +1,110 @@
1
+ # Re-using step definitions
2
+
3
+ One of the advantage of using jest-cucumber-fusion is that it will manage your test suite scope inside its execution
4
+ Your automation code easy to read: it reads pretty much like your feature file.
5
+ You can then reuse the same steps repeatedly in multiple scenarios.
6
+
7
+ It is normally recommended that your test code contain as little logic as possible, with common setup logic abstracted into other modules (e.g., test data creation), so there really shouldn't be much duplicated code in the first place. To further reduce duplicated code, you could do something like this:
8
+ ```gherkin
9
+ # reuse-rocket.feature
10
+ Feature: Rocket reuse
11
+
12
+ Scenario: Reusing a SpaceX rocket
13
+ Given I am Elon Musk and I launched a rocket in space already
14
+ Then I'm happy
15
+ ```
16
+
17
+ Write you step definitions as usual but require (or import) your shared step definition file
18
+ ```javascript
19
+ // reuse-rocket.steps.js
20
+ const { Given, Fusion } = require( 'jest-cucumber-fusion' )
21
+
22
+
23
+
24
+ Given( 'I am Elon Musk and I launched a rocket in space already', () => {
25
+ const hasLaunchedARocket = true
26
+ expect( hasLaunchedARocket ).toBe( true )
27
+ } )
28
+
29
+ ///
30
+ ///This is our shared test code
31
+ ///
32
+ require( './reuse-code' )
33
+
34
+
35
+ Fusion( '../reuse-rocket.feature' )
36
+ ```
37
+
38
+ Place you shared step definitions in a shared step definition file, jest-cucumber-fusion takes care of the rest
39
+ ```javascript
40
+ // reuse-code.js
41
+ const { Then } = require( 'jest-cucumber-fusion' )
42
+
43
+ Then( 'I\'m happy', () => {
44
+ const localHappy = true
45
+ expect( localHappy ).toBe( true )
46
+ } )
47
+ ```
48
+
49
+
50
+ ### Managing dependencies
51
+ Though it is not best practice, you sometime need to pass value to the shared step definitions file, like in this example:
52
+
53
+ ```gherkin
54
+ # reuse-rocket.feature
55
+ Feature: Rocket reuse
56
+
57
+ Scenario: Reusing a SpaceX rocket
58
+ Given I am Elon Musk and I launched a rocket in space already
59
+ When I relaunch the rocket
60
+ Then the rocket end up in space again
61
+ And I drop my mic
62
+ ```
63
+
64
+
65
+ You will now need to encapsulate the variables in an accessor function and pass the accessor to the constructor/init of your file
66
+ ```javascript
67
+ // reuse-rocket.steps.js
68
+ const { Given, Fusion } = require( 'jest-cucumber-fusion' )
69
+
70
+ const { Rocket } = require( '../../../src/rocket' )
71
+
72
+ let rocket
73
+ function getCurrentRocket() {
74
+ return rocket
75
+ }
76
+
77
+ Given( 'I am Elon Musk and I launched a rocket in space already', () => {
78
+ rocket = new Rocket()
79
+ } )
80
+
81
+
82
+ require( './reuse-code' )( getCurrentRocket )
83
+
84
+
85
+ Fusion( '../reuse-definition.feature' )
86
+ ```
87
+
88
+
89
+ Inside you shared step file, be careful to call the accessor inside your test step function not outside
90
+ ```javascript
91
+ // reuse-code.js
92
+ const { When, Then, And } = require( 'jest-cucumber-fusion' )
93
+
94
+ And( 'I drop my mic', () => {
95
+ const micDropped = true
96
+ expect( micDropped ).toBe( true )
97
+ } )
98
+
99
+ module.exports = exports = function( fnRocket ) {
100
+ When( 'I relaunch the rocket', () => {
101
+ const rocketUsed = fnRocket()
102
+ rocketUsed.launch()
103
+ } )
104
+
105
+ Then( 'the rocket end up in space again', () => {
106
+ const rocketUsed = fnRocket()
107
+ expect( rocketUsed.isInSpace ).toBe(true)
108
+ } )
109
+ }
110
+ ```
@@ -0,0 +1,16 @@
1
+ # Running the examples
2
+
3
+ Note that examples are provided in both ECMAScript and TypeScript.
4
+
5
+ First, build jest-cucumber-fusion:
6
+
7
+ ```
8
+ $ npm install
9
+ ```
10
+
11
+ ## Running examples from the CMD line
12
+
13
+
14
+ ```
15
+ $ npm test
16
+ ```
@@ -0,0 +1,43 @@
1
+ # Scenario outlines
2
+
3
+ ```gherkin
4
+ Feature: Online sales
5
+
6
+ Scenario Outline: Selling an item
7
+ Given I have a(n) <Item>
8
+ When I sell the <Item>
9
+ Then I should get $<Amount>
10
+
11
+ Examples:
12
+
13
+ | Item | Amount |
14
+ | Autographed Neil deGrasse Tyson book | 100 |
15
+ | Rick Astley t-shirt | 22 |
16
+ | An idea to replace EVERYTHING with blockchains | $0 |
17
+ ```
18
+
19
+ ```javascript
20
+ const { Before, Given, When, Then, Fusion } = require( '../../../../src' )
21
+
22
+ const { OnlineSales } = require( '../../../src/online-sales' )
23
+ let onlineSales
24
+ let salesPrice
25
+
26
+
27
+ Before( () => { onlineSales = new OnlineSales() } )
28
+
29
+ Given( /^I have a\(n\) (.*)$/, item => {
30
+ onlineSales.listItem(item)
31
+ } )
32
+
33
+ When( /^I sell the (.*)$/, item => {
34
+ salesPrice = onlineSales.sellItem(item)
35
+ } )
36
+
37
+ Then( /^I should get \$(\d+)$/, expectedSalesPrice => {
38
+ expect(salesPrice).toBe(parseInt(expectedSalesPrice))
39
+ } )
40
+
41
+
42
+ Fusion( '../scenario-outlines.feature' )
43
+ ```
@@ -0,0 +1,37 @@
1
+ ## Step definition arguments
2
+
3
+ ```gherkin
4
+ Feature: Getting rich writing software
5
+
6
+ Scenario: Depositing a paycheck
7
+ Given my account balance is $10
8
+ When I get paid $1000000 for writing some awesome code
9
+ Then my account balance should be $1000010
10
+ ```
11
+
12
+ ```javascript
13
+ const { Before, Given, When, Then, Fusion } = require( '../../../../src' )
14
+
15
+ const { BankAccount } = require( '../../../src/bank-account' )
16
+ let myAccount
17
+
18
+
19
+ Before( () => { myAccount = new BankAccount() } )
20
+
21
+
22
+ Given(/^my account balance is \$(\d+)$/, balance => {
23
+ myAccount.deposit(parseInt(balance))
24
+ } )
25
+
26
+ When(/^I get paid \$(\d+) for writing some awesome code$/, paycheck => {
27
+ myAccount.deposit(parseInt(paycheck))
28
+ } )
29
+
30
+ Then(/^my account balance should be \$(\d+)$/, expectedBalance => {
31
+ expect(myAccount.balance).toBe(parseInt(expectedBalance))
32
+ } )
33
+
34
+
35
+ Fusion( '../using-dynamic-values.feature' )
36
+
37
+ ```
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@g_package/jest-cucumber-fusion",
3
+ "version": "1.0.0",
4
+ "description": "Write cucumber test as part of a jest run (including coverage)",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "scripts": {
8
+ "test": "jest --color",
9
+ "coverage": "jest --coverage",
10
+ "commit": "git-cz",
11
+ "semantic-release": "semantic-release",
12
+ "fmt": "npx prettier --write ."
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/gotreasa/jest-cucumber-fusion.git"
17
+ },
18
+ "keywords": [
19
+ "jest",
20
+ "cucumber",
21
+ "BDD",
22
+ "gherkin"
23
+ ],
24
+ "dependencies": {
25
+ "callsites": "~3.1.0",
26
+ "jest": "^30.4.2",
27
+ "jest-cucumber": "^4.5.0"
28
+ },
29
+ "devDependencies": {
30
+ "cz-conventional-changelog": "^3.3.0",
31
+ "prettier": "2.3.2",
32
+ "semantic-release": "^25.0.5"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "config": {
38
+ "commitizen": {
39
+ "path": "./node_modules/cz-conventional-changelog"
40
+ }
41
+ },
42
+ "release": {
43
+ "plugins": [
44
+ "@semantic-release/commit-analyzer",
45
+ "@semantic-release/release-notes-generator",
46
+ [
47
+ "@semantic-release/github",
48
+ {
49
+ "assets": [
50
+ "dist/**"
51
+ ]
52
+ }
53
+ ],
54
+ [
55
+ "@semantic-release/npm",
56
+ {
57
+ "npmPublish": true
58
+ }
59
+ ]
60
+ ],
61
+ "parserOpts": {
62
+ "mergePattern": "Merged PR .*:"
63
+ }
64
+ },
65
+ "author": "B-Yond",
66
+ "license": "Apache-2.0",
67
+ "bugs": {
68
+ "url": "https://github.com/gotreasa/jest-cucumber-fusion/issues"
69
+ },
70
+ "homepage": "https://github.com/gotreasa/jest-cucumber-fusion#readme",
71
+ "jest": {
72
+ "testMatch": [
73
+ "**/*.steps.js"
74
+ ],
75
+ "coveragePathIgnorePatterns": [
76
+ "/node_modules/",
77
+ "/test/"
78
+ ],
79
+ "coverageDirectory": "./coverage/",
80
+ "collectCoverage": true
81
+ }
82
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ // Type definitions for jest-cucumber-fusion 0.6
2
+ // Project: https://github.com/b-yond-infinite-network/jest-cucumber-fusion#readme
3
+ // Definitions by: Pelle Johnsen <https://github.com/pjoe>
4
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+ // Minimum TypeScript Version: 3.4
6
+
7
+ import { loadFeature } from "jest-cucumber";
8
+
9
+ export type CallBack = (
10
+ ...args: ReadonlyArray<string | Array<Record<string, string>>>
11
+ ) => void | Promise<void>;
12
+
13
+ export function Given(name: string | RegExp, callback: CallBack): void;
14
+ export function When(name: string | RegExp, callback: CallBack): void;
15
+ export function Then(name: string | RegExp, callback: CallBack): void;
16
+ export function And(name: string | RegExp, callback: CallBack): void;
17
+ export function But(name: string | RegExp, callback: CallBack): void;
18
+
19
+ export function Before(callback: () => void | Promise<void>): void;
20
+ export function After(callback: () => void | Promise<void>): void;
21
+
22
+ export function Fusion(
23
+ feature: string,
24
+ options?: Parameters<typeof loadFeature>[1]
25
+ ): void;