Skip to content

Commit

Permalink
accept provided configuration as array of argv (#2374)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss committed Jan 16, 2024
1 parent 23e0155 commit 47dbe42
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber.

## [Unreleased]
### Changed
- Allow `provided` configuration to be an array ([#2374](https://github.com/cucumber/cucumber-js/pull/2374))

## [10.3.0] - 2024-01-15
### Added
Expand Down
2 changes: 1 addition & 1 deletion exports/api/report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface IConfiguration {
export interface ILoadConfigurationOptions {
file?: string | false;
profiles?: string[];
provided?: Partial<IConfiguration> | string;
provided?: Partial<IConfiguration> | string[] | string;
}

// @public
Expand Down
9 changes: 9 additions & 0 deletions src/api/load_configuration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ describe('loadConfiguration', function () {
})
afterEach(async () => teardownEnvironment(environment))

it('should handle configuration directly provided as an array of strings', async () => {
const { useConfiguration } = await loadConfiguration(
{ provided: ['--world-parameters', '{"foo":"bar"}'] },
environment
)

expect(useConfiguration.worldParameters).to.deep.eq({ foo: 'bar' })
})

it('should handle configuration directly provided as a string', async () => {
const { useConfiguration } = await loadConfiguration(
{ provided: `--world-parameters '{"foo":"bar"}'` },
Expand Down
6 changes: 4 additions & 2 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export interface ILoadConfigurationOptions {
* failFast: true,
* parallel: 2
* \}
* @example ["--fail-fast", "--parallel", "2"]
* @example "--fail-fast --parallel 2"
* @remarks
* This can also be provided as a string of argv-style arguments.
* This can also be provided as an array or single string of argv-style
* arguments.
*/
provided?: Partial<IConfiguration> | string
provided?: Partial<IConfiguration> | string[] | string
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/configuration/parse_configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import { checkSchema } from './check_schema'
export function parseConfiguration(
logger: ILogger,
source: string,
definition: Partial<IConfiguration> | string | undefined
definition: Partial<IConfiguration> | string[] | string | undefined
): Partial<IConfiguration> {
if (!definition) {
return {}
}
if (Array.isArray(definition)) {
logger.debug(`${source} configuration value is an array; parsing as argv`)
const { configuration } = ArgvParser.parse([
'node',
'cucumber-js',
...definition,
])
return configuration
}
if (typeof definition === 'string') {
logger.debug(`${source} configuration value is a string; parsing as argv`)
const { configuration } = ArgvParser.parse([
Expand Down

0 comments on commit 47dbe42

Please sign in to comment.