Skip to content

Commit

Permalink
Merging user configuration from file with desired configuration from …
Browse files Browse the repository at this point in the history
…console
  • Loading branch information
beluamat29 committed Dec 29, 2024
1 parent 5ffdac2 commit 3947dfe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class Configuration {

static withConfiguration(aConfiguration) {
const defaultConfiguration = require('./default_configuration.json');
return new this(aConfiguration, defaultConfiguration);
const userConfiguration = require(resolvePathFor(CONFIGURATION_FILE_NAME));
return new this({ ...userConfiguration, ...aConfiguration }, defaultConfiguration);
}
constructor(userConfiguration, defaultConfiguration) {
this.#userConfigurationOptions = userConfiguration;
Expand Down
16 changes: 11 additions & 5 deletions lib/config/parameters_parser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { I18n } from '../i18n/i18n.js';
import { isString } from '../utils.js';

/**
* I transform a list of console parameters into a valid configuration object.
* I can also differentiate between path parameters and configuration parameters.
*/
import { I18n } from '../i18n/i18n.js';
import { isString } from '../utils.js';

export class ParametersParser {

static generateRunConfigurationFromParams(params) {
Expand Down Expand Up @@ -56,11 +56,11 @@ export class ParametersParser {
}

static getPathsAndConfigurationParams(allParams) {
const firstConfigParamIndex = allParams.findIndex(param => this.isConfigurationParam(param));
const firstConfigParamIndex = allParams.findIndex(param => this.isRawConfigurationParam(param));

if (firstConfigParamIndex >= 0) {
const paramsAfterFirstConfigurationParam = allParams.slice(firstConfigParamIndex);
const thereIsPathParamAfterConfigParams = paramsAfterFirstConfigurationParam.some(param => !this.isConfigurationParam(param));
const thereIsPathParamAfterConfigParams = paramsAfterFirstConfigurationParam.some(param => !this.isRawConfigurationParam(param));
if (thereIsPathParamAfterConfigParams) {
throw new Error('Run configuration parameters should always be sent at the end of test paths routes');
}
Expand All @@ -80,6 +80,12 @@ export class ParametersParser {
return this.isFailFastParam(param) || this.isRandomizeParam(param) || this.isLanguageParam(param);
}

static isRawConfigurationParam(param) {
// pre sanitization
const supportedLanguages = I18n.supportedLanguages();
return this.isConfigurationParam(param) || supportedLanguages.includes(param);
}

static isFailFastParam(string) {
return isString(string) && (string === '-f' || string === '--fail-fast');
}
Expand Down

0 comments on commit 3947dfe

Please sign in to comment.