-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: esm support #1589
Merged
Merged
cli: esm support #1589
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
327c8fe
add mjs wrapper
davidjgoss 38e7282
use import instead of require for support code
davidjgoss 964118f
support es2018 compile target
davidjgoss c8943bc
separate cli for esm, override importer fn
davidjgoss 9dc49f6
include mjs wrapper in package
davidjgoss 50da4dc
add feature for testing with esm
davidjgoss 01de7f2
for now, bail if on windows
davidjgoss 9e6b29d
all same exports as cjs entry point
davidjgoss 0f30b12
pivot to single binary with flag and hack to import import
davidjgoss 6743af8
fix feature file wording
davidjgoss 9d10ce1
fix lint and test
davidjgoss b37fb13
skip esm scenario if not node 12 or higher
davidjgoss 68096e6
make it fail with imports in cucumber.js file
davidjgoss 0eaaa0a
make it work for cucumber.js file
davidjgoss 0e36903
make it fail for a custom formatter
davidjgoss c2c7ad5
avoid collision
davidjgoss 23af315
Merge branch 'master' into esm-maybe
davidjgoss eaf2b69
Merge branch 'master' into esm-maybe
davidjgoss 7d34fe3
make importing formatters work
davidjgoss 4a5c7ca
make custom snippets work
davidjgoss a78b63a
Include .mjs files by default if using ESM
davidjgoss a9a8cc3
test with and without parallel
davidjgoss d0ed9cc
unignore windows in esm tests
davidjgoss 52595c0
add cli doc
davidjgoss ca140ce
add changelog entry
davidjgoss 5808b39
rename this
davidjgoss 32a8158
sometimes use `pathToFileURL` as appropriate
davidjgoss a1b6ba6
readd semi
davidjgoss c2f6bd3
rework config builder tests
davidjgoss 5e1da47
further resimplify test
davidjgoss d11087b
improve doco
davidjgoss ad28700
include importer.js in src, copy at build time
davidjgoss 3f2e640
link to docs from changelog entry
davidjgoss 38febb5
put wrapper.mjs in src as well
davidjgoss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,80 @@ | ||
Feature: ES modules support | ||
|
||
cucumber-js works with native ES modules, via a Cli flag `--esm` | ||
|
||
@esm | ||
Scenario Outline: native module syntax works when using --esm | ||
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 "cucumber.js" with: | ||
""" | ||
export default { | ||
'default': '--format message:messages.ndjson', | ||
} | ||
""" | ||
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' | ||
} | ||
} | ||
""" | ||
When I run cucumber-js with `<options> --format ./custom-formatter.js --format-options '{"snippetSyntax": "./custom-snippet-syntax.js"}'` | ||
Then it passes | ||
Examples: | ||
| options | | ||
| --esm | | ||
| --esm --parallel 2 | | ||
|
||
@esm | ||
Scenario: .mjs support code files are matched by default when using --esm | ||
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 with `--esm` | ||
Then it passes | ||
|
||
Scenario: native module syntax doesn't work without --esm | ||
Given a file named "features/a.feature" with: | ||
""" | ||
Feature: | ||
Scenario: | ||
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() {}); | ||
""" | ||
When I run cucumber-js | ||
Then it fails |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ESM purely additive (ie require is still supported)?
If not, would seem like using this requires custom formatters used would also need to be written in ESM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ESM is additive. If enabled, it'll use
import()
to load all user code (steps/hooks, formatters, snippets, and config file). If any of this user code is CommonJS and hasrequire()
s in it, that will still work fine - you canimport()
CommonJS modules, but you can'trequire()
ES modules.Eventually (after dropping Node 12 support, I think) we'll be able to just always use
import()
and not need the flag.(Hope I've understood the question right!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I've pushed some documentation improvements to this effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!