Skip to content

Commit 5634903

Browse files
authored
Merge pull request #2 from cucumber/master
Updating from master
2 parents d173e64 + 75d6acd commit 5634903

28 files changed

+616
-261
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ node_modules
1111
tmp/
1212
usage.txt
1313
yarn-error.log
14+
.vscode

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
1111

1212
### Added
1313

14-
- Support attachments that are already base64-encoded via a prefix on the MIME type e.g. `this.attach(base64String, 'base64:image/png')` ([#1552](https://github.com/cucumber/cucumber-js/pull/1552))
14+
* Experimental support for native ES modules via the [`--esm` flag](./docs/cli.md#es-modules-experimental-nodejs-12) ([#1589](https://github.com/cucumber/cucumber-js/pull/1589))
1515

1616
### Changed
1717

@@ -21,8 +21,19 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
2121

2222
### Fixed
2323

24+
## [7.1.0] (2021-04-06)
25+
26+
### Added
27+
28+
- Support attachments that are already base64-encoded via a prefix on the MIME type e.g. `this.attach(base64String, 'base64:image/png')` ([#1552](https://github.com/cucumber/cucumber-js/pull/1552))
29+
- Support tagged rules ([cucumber#1123](https://github.com/cucumber/cucumber/issues/1123))
30+
31+
### Fixed
32+
2433
* Fix types for hook functions so they can return e.g. `'skipped'` ([#1542](https://github.com/cucumber/cucumber-js/pull/1542))
2534
* Display the response of the reports server when an error is returned before failing. ([#1608](https://github.com/cucumber/cucumber-js/pull/1608))
35+
* Remove unnecessary implicit dependency on `long` package ([cucumber#1313](https://github.com/cucumber/cucumber/pull/1313))
36+
* Remove unnecessary transitive dependencies on `react` etc ([cucumber#1308](https://github.com/cucumber/cucumber/pull/1308))
2637

2738
## [7.0.0] (2020-12-21)
2839

@@ -1804,7 +1815,8 @@ be used to get the name / tags of the running scenario. ([#947](https://github.c
18041815
18051816
18061817
<!-- Releases -->
1807-
[Unreleased]: https://github.com/cucumber/cucumber-js/compare/v7.0.0...master
1818+
[Unreleased]: https://github.com/cucumber/cucumber-js/compare/v7.1.0...master
1819+
[7.1.0]: https://github.com/cucumber/cucumber-js/compare/7.1.0-rc.0...7.0.0
18081820
[7.0.0]: https://github.com/cucumber/cucumber-js/compare/7.0.0-rc.0...v7.0.0
18091821
[7.0.0-rc.0]: https://github.com/cucumber/cucumber-js/compare/v6.0.5...v7.0.0-rc.0
18101822
[6.0.5]: https://github.com/cucumber/cucumber-js/compare/v6.0.4...v6.0.5

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
[![OpenCollective](https://opencollective.com/cucumber/backers/badge.svg)](https://opencollective.com/cucumber)
44
[![OpenCollective](https://opencollective.com/cucumber/sponsors/badge.svg)](https://opencollective.com/cucumber)
5-
5+
[![pull requests](https://oselvar.com/api/badge?label=pull%20requests&csvUrl=https%3A%2F%2Fraw.githubusercontent.com%2Fcucumber%2Foselvar-github-metrics%2Fmain%2Fdata%2Fcucumber%2Fcucumber-js%2FpullRequests.csv)](https://oselvar.com/github/cucumber/oselvar-github-metrics/main/cucumber/cucumber-js)
6+
[![issues](https://oselvar.com/api/badge?label=issues&csvUrl=https%3A%2F%2Fraw.githubusercontent.com%2Fcucumber%2Foselvar-github-metrics%2Fmain%2Fdata%2Fcucumber%2Fcucumber-js%2Fissues.csv)](https://oselvar.com/github/cucumber/oselvar-github-metrics/main/cucumber/cucumber-js)
67

78
[![GitHub Actions](https://github.com/cucumber/cucumber-js/workflows/Build/badge.svg)](https://github.com/cucumber/cucumber-js/actions)
89
[![Dependencies](https://david-dm.org/cucumber/cucumber-js.svg)](https://david-dm.org/cucumber/cucumber-js)

dependency-lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ requiredModules:
4343
- 'dist/**/*'
4444
- 'lib/**/*'
4545
- 'node_modules/**/*'
46+
- 'src/importers.js'
4647
- 'tmp/**/*'
4748
root: '**/*.{js,ts}'
4849
stripLoaders: false

docs/cli.md

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ You can pass in format options with `--format-options <JSON>`. The JSON string m
8181

8282
* Suggested use: add with profiles so you can define an object and use `JSON.stringify` instead of writing `JSON` manually.
8383

84+
## ES Modules (experimental) (Node.js 12+)
85+
86+
You can optionally write your support code (steps, hooks, etc) with native ES modules syntax - i.e. using `import` and `export` statements without transpiling.
87+
88+
To enable this, run with the `--esm` flag.
89+
90+
This will also expand the default glob for support files to include the `.mjs` file extension.
91+
92+
As well as support code, these things can also be in ES modules syntax:
93+
94+
- Custom formatters
95+
- Custom snippets
96+
- Your `cucumber.js` config file
97+
98+
You can use ES modules selectively/incrementally - the module loading strategy that the `--esm` flag activates supports both ES modules and CommonJS.
99+
84100
## Colors
85101

86102
Colors can be disabled with `--format-options '{"colorsEnabled": false}'`
@@ -174,31 +190,43 @@ For instance, for ES6 support with [Babel](https://babeljs.io/) 7 add:
174190

175191
This will effectively call `require('@babel/register')` prior to requiring any support files.
176192

177-
### Non JS files
193+
If your files end with an extension other than `js`, make sure to also include the `--require` option to state the required support files. For example, if using [CoffeeScript](https://www.npmjs.com/package/coffeescript):
178194

179-
If your files end in an extension other than `js`, make sure to also include the `--require` option to state the support files to require.
195+
```
196+
--require-module coffeescript/register --require 'features/**/*.coffee'
197+
```
198+
199+
### Typescript
200+
201+
#### With ts-node
180202

181-
For example, with [TypeScript](https://www.typescriptlang.org/):
203+
If you are using [ts-node](https://github.com/TypeStrong/ts-node):
182204

183205
```
184206
--require-module ts-node/register --require 'step-definitions/**/*.ts'
185207
```
186208

187-
or [CoffeeScript](https://www.npmjs.com/package/coffeescript):
209+
> ⚠️ Some TypeScript setups use `esnext` modules by default,
210+
> which doesn't marry well with Node. You may consider using commonjs instead.
211+
> See how to add [extra configuration](#extra-configuration) below.
212+
213+
#### With babel
214+
215+
If you are using babel with [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript):
188216

189217
```
190-
--require-module coffeescript/register --require 'features/**/*.coffee'
218+
--require-module @babel/register --require 'step-definitions/**/*.ts'
191219
```
192220

193-
### Extra configuration
221+
### Extra Configuration
194222

195-
Sometimes the required module (say `@ts-node/register`) needs extra configuration (e.g. you might want to configure it such that it prevents the compiled JS being written out to files, and pass some compiler options). In such cases, create a script (say, `tests.setup.js`):
223+
Sometimes the required module (say `@ts-node/register`) needs extra configuration. For example, you might want to configure it such that it prevents the compiled JS being written out to files, and pass some compiler options. In such cases, create a script (say, `tests.setup.js`):
196224

197225
```js
198226
require('ts-node').register({
199227
transpileOnly: true,
200228
compilerOptions: {
201-
// your compiler options here
229+
"module": "commonjs",
202230
},
203231
});
204232
```

features/esm.feature

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
Feature: ES modules support
2+
3+
cucumber-js works with native ES modules, via a Cli flag `--esm`
4+
5+
@esm
6+
Scenario Outline: native module syntax works when using --esm
7+
Given a file named "features/a.feature" with:
8+
"""
9+
Feature:
10+
Scenario: one
11+
Given a step passes
12+
13+
Scenario: two
14+
Given a step passes
15+
"""
16+
And a file named "features/step_definitions/cucumber_steps.js" with:
17+
"""
18+
import {Given} from '@cucumber/cucumber'
19+
20+
Given(/^a step passes$/, function() {});
21+
"""
22+
And a file named "cucumber.js" with:
23+
"""
24+
export default {
25+
'default': '--format message:messages.ndjson',
26+
}
27+
"""
28+
And a file named "custom-formatter.js" with:
29+
"""
30+
import {SummaryFormatter} from '@cucumber/cucumber'
31+
32+
export default class CustomFormatter extends SummaryFormatter {}
33+
"""
34+
And a file named "custom-snippet-syntax.js" with:
35+
"""
36+
export default class CustomSnippetSyntax {
37+
build(opts) {
38+
return 'hello world'
39+
}
40+
}
41+
"""
42+
When I run cucumber-js with `<options> --format ./custom-formatter.js --format-options '{"snippetSyntax": "./custom-snippet-syntax.js"}'`
43+
Then it passes
44+
Examples:
45+
| options |
46+
| --esm |
47+
| --esm --parallel 2 |
48+
49+
@esm
50+
Scenario: .mjs support code files are matched by default when using --esm
51+
Given a file named "features/a.feature" with:
52+
"""
53+
Feature:
54+
Scenario:
55+
Given a step passes
56+
"""
57+
And a file named "features/step_definitions/cucumber_steps.mjs" with:
58+
"""
59+
import {Given} from '@cucumber/cucumber'
60+
61+
Given(/^a step passes$/, function() {});
62+
"""
63+
When I run cucumber-js with `--esm`
64+
Then it passes
65+
66+
Scenario: native module syntax doesn't work without --esm
67+
Given a file named "features/a.feature" with:
68+
"""
69+
Feature:
70+
Scenario:
71+
Given a step passes
72+
"""
73+
And a file named "features/step_definitions/cucumber_steps.js" with:
74+
"""
75+
import {Given} from '@cucumber/cucumber'
76+
77+
Given(/^a step passes$/, function() {});
78+
"""
79+
When I run cucumber-js
80+
Then it fails

features/rule.feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,31 @@ Feature: Rule keyword
135135
8 steps (1 failed, 1 skipped, 6 passed)
136136
<duration-stat>
137137
"""
138+
139+
Scenario: Tags on Rules are honoured
140+
Given a file named "features/highlander.feature" with:
141+
"""
142+
Feature: a feature
143+
144+
@mytag
145+
Rule: a rule
146+
147+
Example: a scenario
148+
Given a step
149+
"""
150+
And a file named "features/step_definitions/cucumber_steps.js" with:
151+
"""
152+
const {Given} = require('@cucumber/cucumber')
153+
154+
Given('a step', function() {})
155+
"""
156+
When I run cucumber-js with arguments `--tags @mytag` and env ``
157+
Then it passes
158+
And it outputs the text:
159+
"""
160+
.
161+
162+
1 scenario (1 passed)
163+
1 step (1 passed)
164+
<duration-stat>
165+
"""

features/support/hooks.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Before('@debug', function (this: World) {
1313
this.debug = true
1414
})
1515

16-
Before('@spawn', function (this: World) {
16+
Before('@spawn or @esm', function (this: World) {
1717
this.spawn = true
1818
})
1919

@@ -43,6 +43,18 @@ Before(function (
4343
this.localExecutablePath = path.join(projectPath, 'bin', 'cucumber-js')
4444
})
4545

46+
Before('@esm', function (this: World) {
47+
const [majorVersion] = process.versions.node.split('.')
48+
if (Number(majorVersion) < 12) {
49+
return 'skipped'
50+
}
51+
fsExtra.writeJSONSync(path.join(this.tmpDir, 'package.json'), {
52+
name: 'feature-test-pickle',
53+
type: 'module',
54+
})
55+
return undefined
56+
})
57+
4658
Before('@global-install', function (this: World) {
4759
const tmpObject = tmp.dirSync({ unsafeCleanup: true })
4860

features/target_specific_scenarios_by_tag.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@ Feature: Target specific scenarios
3030
"""
3131
const {Given} = require('@cucumber/cucumber')
3232
33-
Given(/^a step is (.*)$/, function() {})
33+
Given('a step', function() {})
3434
"""
3535

3636
Scenario: run a single scenario
3737
When I run cucumber-js with `--tags @a`
38-
Then it fails
38+
Then it passes
3939
And it runs the scenario "first scenario"
4040

4141
Scenario: filter out scenarios with ~
4242
When I run cucumber-js with `--tags "not @b"`
43-
Then it fails
43+
Then it passes
4444
And it runs the scenario "first scenario"
4545

4646
Scenario: merge multiple tag expressions
4747
When I run cucumber-js with `--tags @b --tags "not @c"`
48-
Then it fails
48+
Then it passes
4949
And it runs the scenarios:
5050
| NAME |
5151
| second scenario - Z |
5252

5353
Scenario: run a single scenario outline
5454
When I run cucumber-js with `--tags @b`
55-
Then it fails
55+
Then it passes
5656
And it runs the scenarios:
5757
| NAME |
5858
| second scenario - X |
@@ -61,7 +61,7 @@ Feature: Target specific scenarios
6161

6262
Scenario: run a single scenario outline examples
6363
When I run cucumber-js with `--tags @c`
64-
Then it fails
64+
Then it passes
6565
And it runs the scenarios:
6666
| NAME |
6767
| second scenario - X |

0 commit comments

Comments
 (0)