Skip to content

Commit 8eb3145

Browse files
advance512charlierudolph
authored andcommitted
add snippet interface "async-await" (#1003)
1 parent 73df8eb commit 8eb3145

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
1212
* can now use glob patterns for selecting what features to run
1313
* update `--require` to support glob patterns
1414
* add `--require-module` to require node modules before support code is loaded
15+
* add snippet interface "async-await"
1516

1617
#### Deprecations
1718

docs/cli.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Undefined steps snippets are printed in javascript using the callback interface
8888
### Interface
8989

9090
Override the snippet interface with `--format-options '{"snippetInterface": "<interface>"}'`.
91-
Valid interfaces are 'callback', 'generator', 'promise', or 'synchronous'.
91+
Valid interfaces are 'async-await', 'callback', 'generator', 'promise', or 'synchronous'.
9292

9393
### Syntax
9494

docs/custom_snippet_syntaxes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* See the [JavaScript syntax](/src/formatter/step_definition_snippet_builder/javascript_snippet_syntax.js) and the [custom snippet syntax](/features/step_definition_snippets_custom_syntax.feature) for examples.
44
* Arguments passed to the constructor:
5-
* `snippetInterface` - string equal to one of the following: 'callback', 'generator', 'promise', or 'synchronous'
5+
* `snippetInterface` - string equal to one of the following: 'async-await', 'callback', 'generator', 'promise', or 'synchronous'
66
* Arguments passed to `build` method:
77
* An object with the following keys:
88
* `comment`: a comment to be placed at the top of the function

features/step_definition_snippets_custom_syntax.feature

+6-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ Feature: step definition snippets custom syntax
5555
"""
5656

5757
Examples:
58-
| INTERFACE | SNIPPET_PARAMETERS_AND_ARROW | SNIPPET_IMPLEMENTATION |
59-
| callback | (done) -> | done null, 'pending' |
60-
| generator | -> | 'pending' |
61-
| promise | -> | 'pending' |
62-
| synchronous | -> | 'pending' |
58+
| INTERFACE | SNIPPET_PARAMETERS_AND_ARROW | SNIPPET_IMPLEMENTATION |
59+
| callback | (done) -> | done null, 'pending' |
60+
| generator | -> | 'pending' |
61+
| promise | -> | 'pending' |
62+
| async-await | -> | 'pending' |
63+
| synchronous | -> | 'pending' |

features/step_definition_snippets_interfaces.feature

+1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ Feature: step definition snippets custom syntax
2727
| callback | function (callback) | callback(null, 'pending') |
2828
| generator | function *() | return 'pending' |
2929
| promise | function () | return 'pending' |
30+
| async-await | async function () | return 'pending' |
3031
| synchronous | function () | return 'pending' |

src/formatter/step_definition_snippet_builder/javascript_snippet_syntax.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export default class JavaScriptSnippetSyntax {
77

88
build({ comment, generatedExpressions, functionName, stepParameterNames }) {
99
let functionKeyword = 'function '
10-
if (this.snippetInterface === 'generator') {
10+
if (this.snippetInterface === 'async-await') {
11+
functionKeyword = 'async ' + functionKeyword
12+
} else if (this.snippetInterface === 'generator') {
1113
functionKeyword += '*'
1214
}
1315

0 commit comments

Comments
 (0)