@g_package/jest-cucumber-fusion 2.0.0 → 3.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.
- package/README.md +444 -38
- package/dist/THIRD_PARTY_LICENSES.txt +91 -0
- package/dist/index.cjs +9917 -0
- package/dist/index.d.cts +145 -0
- package/package.json +60 -10
- package/scripts/prepare-hooks.js +23 -0
- package/src/code-suggestion.js +240 -0
- package/src/configuration.js +147 -0
- package/src/feature-source.js +322 -0
- package/src/index.d.ts +123 -13
- package/src/index.js +153 -420
- package/src/keywords.js +56 -0
- package/src/scenario-name.js +128 -0
- package/src/shared-state.js +36 -0
- package/src/step-argument.js +56 -0
- package/src/step-matching.js +89 -0
- package/src/tag-filter.js +90 -0
- package/src/test-registration.js +178 -0
- package/src/value-description.js +26 -0
- package/.prettierignore +0 -16
- package/.prettierrc.json +0 -0
- package/codecov +0 -0
- package/codecov.SHA256SUM +0 -1
- package/codecov.SHA256SUM.sig +0 -16
- package/docs/AdditionalConfiguration.md +0 -155
- package/docs/GherkinTables.md +0 -61
- package/docs/Language.md +0 -76
- package/docs/ReusingStepDefinitions.md +0 -110
- package/docs/RunningTheExamples.md +0 -16
- package/docs/ScenarioOutlines.md +0 -43
- package/docs/StepDefinitionArguments.md +0 -37
- package/docs/product/expectations/fix-l2-outline-regex/outline-regex-binds.md +0 -148
- package/docs/product/expectations/fix-l4-escaped-parens-outline/escaped-parens-bind-in-outlines.md +0 -106
- package/docs/product/expectations/fix-m3-singleton-reset/clean-slate-per-feature.md +0 -133
- package/test/specs/features/basic-scenarios.feature +0 -28
- package/test/specs/features/l3-step-argument-delivery.feature +0 -44
- package/test/specs/features/language.feature +0 -41
- package/test/specs/features/m6-hooks-once-per-test.feature +0 -21
- package/test/specs/features/m6-hooks-outline-only.feature +0 -12
- package/test/specs/features/reuse-definition.feature +0 -13
- package/test/specs/features/scenario-outline2.feature +0 -73
- package/test/specs/features/scenario-outlines.feature +0 -88
- package/test/specs/features/step-definitions/ambiguous-step-shadowing.steps.js +0 -92
- package/test/specs/features/step-definitions/basic-scenarios.steps.js +0 -62
- package/test/specs/features/step-definitions/fuzz-properties.steps.js +0 -170
- package/test/specs/features/step-definitions/hook-error.steps.js +0 -59
- package/test/specs/features/step-definitions/l2-outline-edge-cases.steps.js +0 -327
- package/test/specs/features/step-definitions/l3-step-argument-delivery.steps.js +0 -191
- package/test/specs/features/step-definitions/l4-escaped-parens-outline.steps.js +0 -256
- package/test/specs/features/step-definitions/language.steps.js +0 -86
- package/test/specs/features/step-definitions/m1-before-hooks-clobber.steps.js +0 -64
- package/test/specs/features/step-definitions/m2-duplicate-matcher.steps.js +0 -60
- package/test/specs/features/step-definitions/m3-singleton-reset.steps.js +0 -275
- package/test/specs/features/step-definitions/m4-callsite-resolution.steps.js +0 -76
- package/test/specs/features/step-definitions/m5-errors-false-silent-skip.steps.js +0 -80
- package/test/specs/features/step-definitions/m6-hooks-once-per-test.steps.js +0 -90
- package/test/specs/features/step-definitions/missing-feature-file.steps.js +0 -23
- package/test/specs/features/step-definitions/reuse-code.js +0 -22
- package/test/specs/features/step-definitions/reuse-definition.steps.js +0 -30
- package/test/specs/features/step-definitions/scenario-outline2.steps.js +0 -57
- package/test/specs/features/step-definitions/scenario-outlines.steps.js +0 -110
- package/test/specs/features/step-definitions/undefined-step.steps.js +0 -39
- package/test/specs/features/step-definitions/using-dynamic-values.steps.js +0 -70
- package/test/specs/features/step-definitions/using-gherkin-tables.steps.js +0 -42
- package/test/specs/features/undefined-step.feature +0 -4
- package/test/specs/features/using-dynamic-values.feature +0 -34
- package/test/specs/features/using-gherkin-tables.feature +0 -16
- package/test/src/bank-account.js +0 -17
- package/test/src/online-sales.js +0 -33
- package/test/src/rocket.js +0 -13
- package/test/src/todo-list.js +0 -20
package/.prettierignore
DELETED
package/.prettierrc.json
DELETED
|
File without changes
|
package/codecov
DELETED
|
Binary file
|
package/codecov.SHA256SUM
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ca1d64196d2d34771084afe76ea657d581bf628e31d993ff8e52ea09cc88a56d codecov
|
package/codecov.SHA256SUM.sig
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
-----BEGIN PGP SIGNATURE-----
|
|
2
|
-
|
|
3
|
-
iQIzBAABCgAdFiEEJwNOf9uFDgu8LGL/gGuyiu13mGkFAmpO+3UACgkQgGuyiu13
|
|
4
|
-
mGm0UxAAne5/lA7YQHQlWt455twIGwZgcSX13LTQw45+goIfZC7IGDQ7J6/kLyJG
|
|
5
|
-
sGvkfSmYEODgsgo6474CWcm16VPMZa3QWa4z6EdfyNHhDo5nNe358ZPA1dOemMKZ
|
|
6
|
-
eV2/9WpDcIEIAhsCj8HKjNjsLBcGrAQRbOw2tABg2dbE8Yg94SMdEqjMCswOQn3i
|
|
7
|
-
OPsybWDjbAdqUVIWylUXbned5/hVnzNAMeo6WvC5+LNw1iS+8rzSIUu5iSxCz9jV
|
|
8
|
-
XBe0ZNZ/z1jLZ0NHQXWoOWVT6aHI3Aml/V+ttduuSPwVqWUtqT+XWnnxXJlkt3fQ
|
|
9
|
-
uB8Fy9NBkj5qkls81pUyt0Z9QuMvnI/OxWiUZ6jOEItiZMkK87ryPiheBoaU4kuf
|
|
10
|
-
fcpoRz/EVNsAgcrHBFQCiam7I32h5R5O9orDiU4pKzahSdgelnvOPIZQzSKT5m/M
|
|
11
|
-
50tuts7npVQib2op7XCv+6d3t8ZnUHzXnqiej6n/vWxE3nWJiw39a5ww7RDO1RQB
|
|
12
|
-
8oNPX3qvPGpNmspXSf57oLyJqiSs4t7B9yIacCMPnlVDZt3MseXP/UHH7cXMmRuX
|
|
13
|
-
bU2mkdieBgkGtkNkB76sp/ob5FWQmynW1+Q3ZcDGrGeysnRgDGWD2Yy92lcABZDc
|
|
14
|
-
DXolC9kpvP+UrUXG5XSTIKksMbH4YacgNIKHzwyhOgViMLWBA4g=
|
|
15
|
-
=fH2Y
|
|
16
|
-
-----END PGP SIGNATURE-----
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
# Configuration Options
|
|
2
|
-
|
|
3
|
-
## Disabling scenario / step definition validation
|
|
4
|
-
|
|
5
|
-
Cucumber's approach is to start with your feature file and execute the step definitions in the order defined in the feature file. In contrast, jest-cucumber scenarios are merely Jest tests. In order to provide the same ability as Cucumber to keep the feature files and step definitions in sync, jest-cucumber validates your step definitions against the feature file.
|
|
6
|
-
|
|
7
|
-
By default, this step definition / feature file validation is enabled. If you have scenarios that are defined in the feature file, but not in your step definitions for that feature file, jest-cucumber will raise an error (and provide starter code). If you have scenarios defined in your step definitions for that aren't in your feature file, jest-cucumber will also raise an error. Additionally, jest-cucumber also validates that the steps you define within your scenarios match the steps that are defined in the feature file, and are in the same order.
|
|
8
|
-
|
|
9
|
-
If you would prefer not to have more control over what validation occurs the following options are available:
|
|
10
|
-
|
|
11
|
-
```javascript
|
|
12
|
-
const { Given, When, Then, And, But, Fusion } = require( 'jest-cucumber-fusion' )
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//your javascript tests
|
|
16
|
-
//....
|
|
17
|
-
//Given( ...
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Fusion( 'rocket-launching.feature', {
|
|
22
|
-
errors: {
|
|
23
|
-
missingScenarioInStepDefinitions: true, // Error when a scenario is in the feature file, but not in the step definition
|
|
24
|
-
missingStepInStepDefinitions: true, // Error when a step is in the feature file, but not in the step definitions
|
|
25
|
-
missingScenarioInFeature: true, // Error when a scenario is in the step definitions, but not in the feature
|
|
26
|
-
missingStepInFeature: true, // Error when a step is in the step definitions, but not in the feature
|
|
27
|
-
}
|
|
28
|
-
} )
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Tag filtering
|
|
32
|
-
|
|
33
|
-
You can specify a tag filter. Tag filters will cause any scenario that is filtered out via a tag filter to be skipped.
|
|
34
|
-
|
|
35
|
-
For example, consider the following feature file:
|
|
36
|
-
|
|
37
|
-
```gherkin
|
|
38
|
-
Feature: Tagged scenarios
|
|
39
|
-
|
|
40
|
-
@included
|
|
41
|
-
Scenario: Tagged scenario that is included
|
|
42
|
-
Given my scenario has a tag that is included in my jest-cucumber step definitions tag filter
|
|
43
|
-
But I don't have that scenario defined in my step definitions
|
|
44
|
-
When I execute my jest-cucumber scenarios
|
|
45
|
-
Then jest-cucumber should show me an error
|
|
46
|
-
|
|
47
|
-
@excluded
|
|
48
|
-
Scenario: Tagged scenario that is not included
|
|
49
|
-
Given my scenario has a tag that is NOT included in my jest-cucumber step definitions tag filter
|
|
50
|
-
But I don't have that scenario defined in my step definitions
|
|
51
|
-
When I execute my jest-cucumber scenarios
|
|
52
|
-
Then jest-cucumber should NOT show me an error
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Consider the following step definitions file:
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
const { Given, When, Then, And, But, Fusion } = require( 'jest-cucumber-fusion' )
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
//your javascript tests
|
|
62
|
-
//....
|
|
63
|
-
//Given( ...
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Fusion( 'rocket-launching.feature', { tagFilter: '@included and not @excluded' } )
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
In this case, the scenario tagged `@included` will be run, and the scenario tagged `@excluded` will be skipped. The tag filtering expressions are very powerful and can include `not`, `and`, `or`, as well as parenthesis.
|
|
71
|
-
|
|
72
|
-
## Scenario title templates
|
|
73
|
-
|
|
74
|
-
In some cases, having more control over the scenario titles is desired. For example, imagine scenarios that are tagged with with issue ids like so:
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
Feature: Tagged scenarios
|
|
78
|
-
|
|
79
|
-
@issue-1234
|
|
80
|
-
Scenario: Scenario tagged with issue
|
|
81
|
-
...
|
|
82
|
-
...
|
|
83
|
-
...
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Use a `scenarioNameTemplate` function to be provided to generate the scenario title as desired. For example:
|
|
87
|
-
|
|
88
|
-
```javascript
|
|
89
|
-
const { Given, When, Then, And, But, Fusion } = require( 'jest-cucumber-fusion' )
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//your javascript tests
|
|
93
|
-
//....
|
|
94
|
-
//Given( ...
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
Fusion( 'rocket-launching.feature', {
|
|
99
|
-
scenarioNameTemplate: (vars) => {
|
|
100
|
-
return `${vars.scenarioTitle} (${vars.scenarioTags.join(',')})`
|
|
101
|
-
}
|
|
102
|
-
} )
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
The output scenario title in this case would be `Scenario tagged with issue (issue-1234)`.
|
|
106
|
-
|
|
107
|
-
The following info is available in the `vars` argument:
|
|
108
|
-
|
|
109
|
-
* `featureTitle` - string
|
|
110
|
-
* `featureTags` - string[]
|
|
111
|
-
* `scenarioTitle` - string
|
|
112
|
-
* `scenarioTags` - string[]
|
|
113
|
-
|
|
114
|
-
## Relative feature file paths
|
|
115
|
-
|
|
116
|
-
It might feel more natural to load feature files with paths relative to the file loading the feature, instead of relative to the project root. This is possible with help of the `loadRelativePath` flag:
|
|
117
|
-
|
|
118
|
-
```javascript
|
|
119
|
-
Fusion( 'rocket-launching.feature', { loadRelativePath: true } )
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Please note that the path will be relative to the file that calls `Fusion`, so if you use helper files which call `Fusion` for you this might lead to unexpected results.
|
|
123
|
-
Like all other flags you can set the flag globally to always use relative imports.
|
|
124
|
-
|
|
125
|
-
## Global configuration
|
|
126
|
-
|
|
127
|
-
To avoid repeating the same configuration settings in every step definition file, it is also possible to specify configuration parameters globally. Note that configuration settings specified in step definition files take precedence over global configuration.
|
|
128
|
-
|
|
129
|
-
To enable global configuration, you have to use the jest-cucumber global configuration.
|
|
130
|
-
First specify a configuration JavaScript file in your the `setupFiles` section of your Jest configuration like so:
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
{
|
|
134
|
-
...
|
|
135
|
-
"setupFiles": [
|
|
136
|
-
"./jest-cucumber-config"
|
|
137
|
-
],
|
|
138
|
-
...
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
And setup the configuration JavaScript file, like so:
|
|
143
|
-
|
|
144
|
-
```javascript
|
|
145
|
-
//jest-cucumber-config.js
|
|
146
|
-
|
|
147
|
-
const setJestCucumberConfiguration = require('jest-cucumber').setJestCucumberConfiguration;
|
|
148
|
-
|
|
149
|
-
setJestCucumberConfiguration({
|
|
150
|
-
tagFilter: '@ui and not @slow',
|
|
151
|
-
scenarioNameTemplate: (vars) => {
|
|
152
|
-
return ` ${vars.featureTitle} - ${vars.scenarioTitle}}`;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
```
|
package/docs/GherkinTables.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# Gherkin tables
|
|
2
|
-
|
|
3
|
-
```gherkin
|
|
4
|
-
Feature: Todo List
|
|
5
|
-
|
|
6
|
-
Scenario: Adding an item to my todo list
|
|
7
|
-
Given my todo list currently looks as follows:
|
|
8
|
-
| TaskName | Priority |
|
|
9
|
-
| Fix bugs in my code | medium |
|
|
10
|
-
| Document my hours | medium |
|
|
11
|
-
When I add the following task:
|
|
12
|
-
| TaskName | Priority |
|
|
13
|
-
| Watch cat videos on YouTube all day | high |
|
|
14
|
-
Then I should see the following todo list:
|
|
15
|
-
| TaskName | Priority |
|
|
16
|
-
| Watch cat videos on YouTube all day | high |
|
|
17
|
-
| Sign up for unemployment | high |
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
const { Before, After, Given, When, Then, Fusion } = require( 'jest-cucumber-fusion' )
|
|
22
|
-
|
|
23
|
-
const { TodoList } = require( '../../src/todo-list' )
|
|
24
|
-
let todoList
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Before( () => { todoList = new TodoList(); } )
|
|
28
|
-
|
|
29
|
-
Given( 'my todo list currently looks as follows:', table => {
|
|
30
|
-
table.forEach(row => {
|
|
31
|
-
todoList.add( {
|
|
32
|
-
name: row.TaskName,
|
|
33
|
-
priority: row.Priority
|
|
34
|
-
} )
|
|
35
|
-
} )
|
|
36
|
-
} )
|
|
37
|
-
|
|
38
|
-
When( 'I add the following task:', table => {
|
|
39
|
-
todoList.add({
|
|
40
|
-
name: table[0].TaskName,
|
|
41
|
-
priority: table[0].Priority
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
Then( 'I should see the following todo list:', table => {
|
|
46
|
-
expect(todoList.items.length).toBe(table.length)
|
|
47
|
-
|
|
48
|
-
table.forEach((row, index) => {
|
|
49
|
-
expect(todoList.items[index].name).toBe(table[index].TaskName)
|
|
50
|
-
expect(todoList.items[index].priority).toBe(table[index].Priority)
|
|
51
|
-
} )
|
|
52
|
-
} )
|
|
53
|
-
|
|
54
|
-
After( () => {
|
|
55
|
-
const emptyTodo = new TodoList()
|
|
56
|
-
emptyTodo.add( { name: 'Empty on purpose', priority: 'so low' } )
|
|
57
|
-
} )
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Fusion( '../features/using-gherkin-tables.feature' )
|
|
61
|
-
```
|
package/docs/Language.md
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
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.
|
|
@@ -1,110 +0,0 @@
|
|
|
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
|
-
```
|
package/docs/ScenarioOutlines.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
```
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
```
|