Skip to content
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

Merged
merged 57 commits into from
Mar 15, 2022
Merged

config: support configuration as objects #1952

merged 57 commits into from
Mar 15, 2022

Conversation

davidjgoss
Copy link
Contributor

@davidjgoss davidjgoss commented Mar 9, 2022

🤔 What's changed?

  • Support objects as well as argv-style strings in configuration files
    • Check them against a schema when loading (kinda the equivalent of what commander does with the argv)
    • Validate the final amalgamated configuration against rules e.g. retryTagFilter with retry
  • Support configuration files being ESM or JSON
    • Check for cucumber.mjs and cucumber.json by default
  • Provide a loadConfiguration function for the new JavaScript API, use it internally and in tests
  • Rationalise discrete modules for configuration, api, and cli without circular dependencies

This 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

  • Support for YAML and environment variables as other configuration mechanisms - we'll likely do these soon though!
  • Adding an entry point and documentation for the new API - will be covered in the next PR

⚡️ What's your motivation?

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt (improvement to code design or tooling without changing behaviour)
  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ 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 and configuration.md being added. Also added docs for some things that weren't covered previously.

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

@@ -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
Copy link
Contributor Author

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 @@
{
Copy link
Contributor Author

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()
Copy link
Contributor Author

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`
Copy link
Contributor Author

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'
Copy link
Contributor Author

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 = {
Copy link
Contributor Author

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>>(
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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 = {
Copy link
Contributor Author

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.

@davidjgoss davidjgoss marked this pull request as ready for review March 13, 2022 20:03
docs/cli.md Outdated Show resolved Hide resolved
Copy link
Contributor

@aurelien-reeves aurelien-reeves left a 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 😅)

docs/configuration.md Outdated Show resolved Hide resolved
docs/configuration.md Show resolved Hide resolved
docs/dry_run.md Show resolved Hide resolved
src/api/run_cucumber_spec.ts Outdated Show resolved Hide resolved
src/api/types.ts Show resolved Hide resolved
src/cli/helpers.ts Outdated Show resolved Hide resolved
src/configuration/default_configuration.ts Show resolved Hide resolved
src/configuration/from_file_spec.ts Show resolved Hide resolved
Copy link
Contributor

@aurelien-reeves aurelien-reeves left a 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!

@davidjgoss davidjgoss merged commit f7419e0 into main Mar 15, 2022
@davidjgoss davidjgoss deleted the feat/config-import branch March 15, 2022 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update profile configuration file
3 participants