You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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 <[email protected]>
* Update features/esm.feature
Co-authored-by: Aurélien Reeves <[email protected]>
* 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 <[email protected]>
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.
4
+
5
+
Example (adapted from [our original example](./nodejs_example.md)):
6
+
7
+
```javascript
8
+
// features/support/steps.mjs
9
+
import { Given, When, Then } from'@cucumber/cucumber'
10
+
import { strictasassert } from'assert'
11
+
12
+
Given('a variable set to {int}', function (number) {
13
+
this.setTo(number)
14
+
})
15
+
16
+
When('I increment the variable by {int}', function (number) {
17
+
this.incrementBy(number)
18
+
})
19
+
20
+
Then('the variable should contain {int}', function (number) {
21
+
assert.equal(this.variable, number)
22
+
})
23
+
```
24
+
25
+
As well as support code, these things can also be in ES modules syntax:
26
+
27
+
- Custom formatters
28
+
- Custom snippets
29
+
30
+
You can use ES modules selectively/incrementally - so you can have a mixture of CommonJS and ESM in the same project.
31
+
32
+
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).
33
+
34
+
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.
0 commit comments