Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "temporarily revert ESM change (#1647)" This reverts commit 084c1f2. * add failing scenario for deep imports * define entry point with dot * make deep imports work via export patterns * move doc to own file * link to doc from readme * add changelog entry * add example to doc * remove confusing comment * remove cli option, use import by default * update documentation * remove redundant describe * fix ordering * Update features/esm.feature Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com> * Update features/esm.feature Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com> * simplify tagging * use import only if a javascript file * add note about no transpilers * inline to avoid confusing reassignment * whoops, re-add try/catch * use require with transpilers; import otherwise * remove pointless return * support .cjs config file * type and import the importer * actually dont import - causes issues Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com>
- Loading branch information
1 parent
6e958f1
commit c35f001
Showing
24 changed files
with
313 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ES Modules (experimental) | ||
|
||
You can optionally write your support code (steps, hooks, etc) with native ES modules syntax - i.e. using `import` and `export` statements without transpiling. This is enabled without any additional configuration, and you can use either of the `.js` or `.mjs` file extensions. | ||
|
||
Example (adapted from [our original example](./nodejs_example.md)): | ||
|
||
```javascript | ||
// features/support/steps.mjs | ||
import { Given, When, Then } from '@cucumber/cucumber' | ||
import { strict as assert } from 'assert' | ||
|
||
Given('a variable set to {int}', function (number) { | ||
this.setTo(number) | ||
}) | ||
|
||
When('I increment the variable by {int}', function (number) { | ||
this.incrementBy(number) | ||
}) | ||
|
||
Then('the variable should contain {int}', function (number) { | ||
assert.equal(this.variable, number) | ||
}) | ||
``` | ||
|
||
As well as support code, these things can also be in ES modules syntax: | ||
|
||
- Custom formatters | ||
- Custom snippets | ||
|
||
You can use ES modules selectively/incrementally - so you can have a mixture of CommonJS and ESM in the same project. | ||
|
||
When using a transpiler for e.g. TypeScript, ESM isn't supported - you'll need to configure your transpiler to output modules in CommonJS syntax (for now). | ||
|
||
The config file referenced for [Profiles](./profiles.md) can only be in CommonJS syntax. In a project with `type=module`, you can name the file `cucumber.cjs`, since Node expects `.js` files to be in ESM syntax in such projects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@esm | ||
Feature: ES modules support | ||
|
||
cucumber-js works with native ES modules | ||
|
||
Scenario Outline: native module syntax works in support code, formatters and snippets | ||
Given a file named "features/a.feature" with: | ||
""" | ||
Feature: | ||
Scenario: one | ||
Given a step passes | ||
Scenario: two | ||
Given a step passes | ||
""" | ||
And a file named "features/step_definitions/cucumber_steps.js" with: | ||
""" | ||
import {Given} from '@cucumber/cucumber' | ||
Given(/^a step passes$/, function() {}); | ||
""" | ||
And a file named "custom-formatter.js" with: | ||
""" | ||
import {SummaryFormatter} from '@cucumber/cucumber' | ||
export default class CustomFormatter extends SummaryFormatter {} | ||
""" | ||
And a file named "custom-snippet-syntax.js" with: | ||
""" | ||
export default class CustomSnippetSyntax { | ||
build(opts) { | ||
return 'hello world' | ||
} | ||
} | ||
""" | ||
And a file named "cucumber.cjs" with: | ||
""" | ||
module.exports = { | ||
'default': '--format summary' | ||
} | ||
""" | ||
When I run cucumber-js with `<options> --format ./custom-formatter.js --format-options '{"snippetSyntax": "./custom-snippet-syntax.js"}' <args>` | ||
Then it passes | ||
Examples: | ||
| args | | ||
| | | ||
| --parallel 2 | | ||
|
||
Scenario: .mjs support code files are matched by default | ||
Given a file named "features/a.feature" with: | ||
""" | ||
Feature: | ||
Scenario: | ||
Given a step passes | ||
""" | ||
And a file named "features/step_definitions/cucumber_steps.mjs" with: | ||
""" | ||
import {Given} from '@cucumber/cucumber' | ||
Given(/^a step passes$/, function() {}); | ||
""" | ||
When I run cucumber-js | ||
Then it passes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.