cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
47 lines (46 loc) • 2.04 kB
JavaScript
import { to_array, to_boolean } from "../../shared/util";
import { C8yDefaultPactPreprocessor, C8yPactPreprocessorDefaultOptions, } from "../../shared/c8ypact";
/**
* The C8yCypressEnvPreprocessor is a preprocessor implementation that uses
* Cypress environment variables to configure C8yPactPreprocessorOptions.
*
* Options are deep merged in the following order:
* - Cypress environment variables
* - C8yPactPreprocessorOptions passed to the apply method
* - C8yPactPreprocessorOptions passed to the constructor
* - Cypress.c8ypact.config value for preprocessor
* - C8yPactPreprocessorDefaultOptions
*/
export class C8yCypressEnvPreprocessor extends C8yDefaultPactPreprocessor {
apply(obj, options) {
super.apply(obj, options);
}
resolveOptions(options) {
let preprocessorConfigValue = {};
if (Cypress.c8ypact?.config?.preprocessor) {
preprocessorConfigValue = Cypress.c8ypact.config.preprocessor;
}
// Build env options, filtering out undefined values
const envOptions = {};
if (Cypress.env("C8Y_PACT_PREPROCESSOR_IGNORE") !== undefined) {
envOptions.ignore = to_array(Cypress.env("C8Y_PACT_PREPROCESSOR_IGNORE"));
}
if (Cypress.env("C8Y_PACT_PREPROCESSOR_OBFUSCATE") !== undefined) {
envOptions.obfuscate = to_array(Cypress.env("C8Y_PACT_PREPROCESSOR_OBFUSCATE"));
}
if (Cypress.env("C8Y_PACT_PREPROCESSOR_PATTERN") !== undefined) {
envOptions.obfuscationPattern = Cypress.env("C8Y_PACT_PREPROCESSOR_PATTERN");
}
if (Cypress.env("C8Y_PACT_PREPROCESSOR_IGNORE_CASE") !== undefined) {
envOptions.ignoreCase = to_boolean(Cypress.env("C8Y_PACT_PREPROCESSOR_IGNORE_CASE"), true);
}
// Merge in priority order (lowest to highest priority)
return {
...C8yPactPreprocessorDefaultOptions,
...preprocessorConfigValue,
...this.options,
...options,
...envOptions,
};
}
}