-
-
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
config: support configuration as objects #1952
Conversation
@@ -95,3 +98,22 @@ Feature: default command line arguments | |||
Scenario: specifying a configuration file that doesn't exist | |||
When I run cucumber-js with `--config doesntexist.js` | |||
Then it fails | |||
|
|||
Scenario: using a JSON file |
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.
No real change needed for this to work, because require()
works for JSON anyway.
@@ -0,0 +1,20 @@ | |||
{ |
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.
A good example of what configuration can look like now.
formats: { | ||
stdout: | ||
[...flatConfiguration.format] | ||
.reverse() |
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.
reverse
because the last one should win if there's several.
export * from './loadSupport' | ||
export * from './runCucumber' | ||
/* | ||
Anything exported here will be publicly available via `@cucumber/cucumber/api` |
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.
The entry point and documentation for the API will be in a follow-up PR.
@@ -0,0 +1,35 @@ | |||
import * as yup from 'yup' |
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.
This is essentially doing for object-based configuration what commander does for argv-based configuration - just checks it's the right shape.
@@ -0,0 +1,25 @@ | |||
import { IConfiguration } from './types' | |||
|
|||
export const DEFAULT_CONFIGURATION: IConfiguration = { |
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.
This has been effectively refactored out of ArgvParser
, because that's no longer the only way we get config.
return undefined | ||
} | ||
|
||
export function mergeConfigurations<T = Partial<IConfiguration>>( |
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.
This does for object-based configuration what the various helpers on ArgvParser
do for argv-based configuration.
} | ||
| false | ||
options?: IParsedArgvFormatOptions | ||
export interface IConfiguration { |
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.
The set of options supported in both files and CLI.
@@ -0,0 +1,9 @@ | |||
import { IConfiguration } from './types' | |||
|
|||
export function validateConfiguration(configuration: IConfiguration): void { |
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.
Once all configuration is loaded and merged together, here we validate if any options are contradictory - schema conformance is already checked earlier.
@@ -33,16 +33,6 @@ export interface IRuntimeOptions { | |||
worldParameters: any | |||
} | |||
|
|||
export const DEFAULT_RUNTIME_OPTIONS: IRuntimeOptions = { |
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.
As above, defaulting now handled as part of configuration load/merge/validate.
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.
Great work, on both options and documentation! 🤩
A few comments, but it looks really great, well done (as usual 😅)
Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com>
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.
Great! Looks good to me!
🤔 What's changed?
retryTagFilter
withretry
cucumber.mjs
andcucumber.json
by defaultloadConfiguration
function for the new JavaScript API, use it internally and in testsconfiguration
,api
, andcli
without circular dependenciesThis is a big diff, much of it comes from shifting the source of truth for configuration away from the argv/commander stuff inwards a bit, since we can now have configuration coming in object form as well. Also lots of documentation changes!
Out of scope
⚡️ What's your motivation?
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
A lot of documentation changes. The intent is to stop everything being talked about in terms of the CLI, and instead cite both config files and CLI as ways to influence things - hence
cli.md
getting a lot shorter andconfiguration.md
being added. Also added docs for some things that weren't covered previously.📋 Checklist: