Best JavaScript code snippet using root
DetoxConfigErrorComposer.js
Source:DetoxConfigErrorComposer.js
...20 _atPath() {21 return this.filepath ? ` at path:\n${this.filepath}` : '.';22 }23 _inTheAppConfig() {24 const { type } = this._getSelectedConfiguration();25 if (type) {26 return `in configuration ${J(this.configurationName)}`;27 }28 return `in the app config`;29 }30 _getSelectedConfiguration() {31 return _.get(this.contents, ['configurations', this.configurationName]);32 }33 _focusOnConfiguration(postProcess = _.identity) {34 const configuration = _.get(this.contents, ['configurations', this.configurationName]);35 if (configuration === undefined) {36 return;37 }38 return {39 configurations: {40 [this.configurationName]: postProcess(configuration)41 },42 };43 }44 _getDeviceConfig(deviceAlias) {45 let config = undefined;46 this._focusOnDeviceConfig(deviceAlias, (value) => {47 config = value;48 return value;49 });50 return config;51 }52 _focusOnDeviceConfig(deviceAlias, postProcess = _.identity) {53 const { type, device } = this._getSelectedConfiguration();54 if (!deviceAlias) {55 if (type || !device) {56 return this._focusOnConfiguration(postProcess);57 } else {58 return this._focusOnConfiguration(c => {59 postProcess(c.device);60 return _.pick(c, 'device');61 });62 }63 }64 return {65 devices: {66 [device]: postProcess(this.contents.devices[device]),67 },68 };69 }70 _focusOnAppConfig(appPath, postProcess = _.identity) {71 const value = _.get(this.contents, appPath);72 return _.set({}, appPath, postProcess(value));73 }74 _resolveSelectedDeviceConfig(alias) {75 if (alias) {76 return this.contents.devices[alias];77 } else {78 const config = this._getSelectedConfiguration();79 return config.type ? config : config.device;80 }81 }82 _ensureProperty(...names) {83 return obj => {84 for (const name of names) {85 return _.set(obj, name, _.get(obj, name));86 }87 };88 }89 // region setters90 setConfigurationName(configurationName) {91 this.configurationName = configurationName || '';92 return this;93 }94 setDetoxConfigPath(filepath) {95 this.filepath = filepath || '';96 return this;97 }98 setDetoxConfig(contents) {99 this.contents = contents || null;100 return this;101 }102 setExtends(value) {103 this._extends = !!value;104 return this;105 }106 // endregion107 // region configuration/index108 noConfigurationSpecified() {109 return new DetoxConfigError({110 message: 'Cannot run Detox without a configuration file.',111 hint: _.endsWith(this.filepath, 'package.json')112 ? `Create an external .detoxrc.json configuration, or add "detox" configuration section to your package.json at:\n${this.filepath}`113 : 'Make sure to create external .detoxrc.json configuration in the working directory before you run Detox.'114 });115 }116 noConfigurationAtGivenPath(givenPath) {117 const message = this._extends118 ? `Failed to find the base Detox config specified in:\n{\n "extends": ${J(givenPath)}\n}`119 : `Failed to find Detox config at ${J(givenPath)}`;120 const hint = this._extends121 ? `Check your Detox config${this._atPath()}`122 : 'Make sure the specified path is correct.';123 return new DetoxConfigError({ message, hint });124 }125 failedToReadConfiguration(unknownError) {126 return new DetoxConfigError({127 message: 'An error occurred while trying to load Detox config from:\n' + this.filepath,128 debugInfo: unknownError,129 });130 }131 noConfigurationsInside() {132 return new DetoxConfigError({133 message: `There are no configurations in the given Detox config${this._atPath()}`,134 hint: `Examine the config:`,135 debugInfo: this.contents ? {136 configurations: undefined,137 ...this.contents,138 } : {},139 inspectOptions: { depth: 1 },140 });141 }142 cantChooseConfiguration() {143 const configurations = this.contents.configurations;144 return new DetoxConfigError({145 message: `Cannot determine which configuration to use from Detox config${this._atPath()}`,146 hint: 'Use --configuration to choose one of the following:\n' + hintList(configurations),147 });148 }149 noConfigurationWithGivenName() {150 const configurations = this.contents.configurations;151 return new DetoxConfigError({152 message: `Failed to find a configuration named ${J(this.configurationName)} in Detox config${this._atPath()}`,153 hint: 'Below are the configurations Detox was able to find:\n' + hintList(configurations),154 });155 }156 configurationShouldNotBeEmpty() {157 const name = this.configurationName;158 const configurations = this.contents.configurations;159 return new DetoxConfigError({160 message: `Cannot use an empty configuration ${J(name)}.`,161 hint: `A valid configuration should have "device" and "app" properties defined, e.g.:\n162{163 "apps": {164*-->"myApp.ios": {165| "type": "ios.app",166| "binaryPath": "path/to/app"167| },168| },169| "devices": {170|*->"simulator": {171|| "type": "ios.simulator",172|| "device": { type: "iPhone 12" }173|| },174||},175||"configurations": {176|| ${J(name)}: {177|*--- "device": "simulator",178*---- "app": "myApp.ios"179 }180 }181}182Examine your Detox config${this._atPath()}`,183 debugInfo: {184 configurations: {185 [name]: configurations[name],186 ...configurations,187 }188 },189 inspectOptions: { depth: 1 }190 });191 }192 // endregion193 // region composeDeviceConfig194 thereAreNoDeviceConfigs(deviceAlias) {195 return new DetoxConfigError({196 message: `Cannot use device alias ${J(deviceAlias)} since there is no "devices" config in Detox config${this._atPath()}`,197 hint: `\198You should create a dictionary of device configurations in Detox config, e.g.:199{200 "devices": {201*-> ${J(deviceAlias)}: {202| "type": "ios.simulator", // or "android.emulator", or etc...203| "device": { "type": "iPhone 12" }, // or e.g.: { "avdName": "Pixel_API_29" }204| }205| },206| "configurations": {207| ${J(this.configurationName)}: {208*---- "device": ${J(deviceAlias)},209 ...210 }211 }212}\n`,213 });214 }215 cantResolveDeviceAlias(alias) {216 return new DetoxConfigError({217 message: `Failed to find a device config ${J(alias)} in the "devices" dictionary of Detox config${this._atPath()}`,218 hint: 'Below are the device configurations Detox was able to find:\n'219 + hintList(this.contents.devices) + '\n\n'220 + `Check your configuration ${J(this.configurationName)}:`,221 debugInfo: this._getSelectedConfiguration(),222 inspectOptions: { depth: 0 },223 });224 }225 deviceConfigIsUndefined() {226 return new DetoxConfigError({227 message: `Missing "device" property in the selected configuration ${J(this.configurationName)}:`,228 hint: `It should be an alias to the device config, or the device config itself, e.g.:229{230 ...231 "devices": {232*-> "myDevice": {233| "type": "ios.simulator", // or "android.emulator", or etc...234| "device": { "type": "iPhone 12" }, // or e.g.: { "avdName": "Pixel_API_29" }235| }236| },237| "configurations": {238| ${J(this.configurationName)}: {239*---- "device": "myDevice", // or { type: 'ios.simulator', ... }240 ...241 },242 ...243 }244}245Examine your Detox config${this._atPath()}`,246 });247 }248 missingDeviceType(deviceAlias) {249 return new DetoxConfigError({250 message: `Missing "type" inside the device configuration.`,251 hint: `Usually, "type" property should hold the device type to test on (e.g. "ios.simulator" or "android.emulator").\n` +252 `Check that in your Detox config${this._atPath()}`,253 debugInfo: this._focusOnDeviceConfig(deviceAlias, this._ensureProperty('type')),254 inspectOptions: { depth: 3 },255 });256 }257 invalidDeviceType(deviceAlias, deviceConfig, innerError) {258 return new DetoxConfigError({259 message: `Invalid device type ${J(deviceConfig.type)} inside your configuration.`,260 hint: `Did you mean to use one of these?261${hintList(deviceAppTypes)}262P.S. If you intended to use a third-party driver, please resolve this error:263${innerError.message}264Please check your Detox config${this._atPath()}`,265 debugInfo: this._focusOnDeviceConfig(deviceAlias, this._ensureProperty('type')),266 inspectOptions: { depth: 3 },267 });268 }269 _invalidPropertyType(propertyName, expectedType, deviceAlias) {270 return new DetoxConfigError({271 message: `Invalid type of ${J(propertyName)} inside the device configuration.\n`272 + `Expected ${expectedType}.`,273 hint: `Check that in your Detox config${this._atPath()}`,274 debugInfo: this._focusOnDeviceConfig(deviceAlias),275 inspectOptions: { depth: 3 },276 });277 }278 _unsupportedPropertyByDeviceType(propertyName, supportedDeviceTypes, deviceAlias) {279 const { type } = this._getDeviceConfig(deviceAlias);280 return new DetoxConfigError({281 message: `The current device type ${J(type)} does not support ${J(propertyName)} property.`,282 hint: `You can use this property only with the following device types:\n` +283 hintList(supportedDeviceTypes) + '\n\n' +284 `Please fix your Detox config${this._atPath()}`,285 debugInfo: this._focusOnDeviceConfig(deviceAlias),286 inspectOptions: { depth: 4 },287 });288 }289 malformedDeviceProperty(deviceAlias, propertyName) {290 switch (propertyName) {291 case 'bootArgs':292 return this._invalidPropertyType('bootArgs', 'a string', deviceAlias);293 case 'utilBinaryPaths':294 return this._invalidPropertyType('utilBinaryPaths', 'an array of strings', deviceAlias);295 case 'forceAdbInstall':296 return this._invalidPropertyType('forceAdbInstall', 'a boolean value', deviceAlias);297 case 'gpuMode':298 return this._invalidPropertyType('gpuMode', "'auto' | 'host' | 'swiftshader_indirect' | 'angle_indirect' | 'guest'", deviceAlias);299 case 'headless':300 return this._invalidPropertyType('headless', 'a boolean value', deviceAlias);301 case 'readonly':302 return this._invalidPropertyType('readonly', 'a boolean value', deviceAlias);303 default:304 throw new DetoxInternalError(`Composing .malformedDeviceProperty(${propertyName}) is not implemented`);305 }306 }307 unsupportedDeviceProperty(deviceAlias, propertyName) {308 switch (propertyName) {309 case 'bootArgs':310 return this._unsupportedPropertyByDeviceType('bootArgs', ['ios.simulator', 'android.emulator'], deviceAlias);311 case 'forceAdbInstall':312 return this._unsupportedPropertyByDeviceType('forceAdbInstall', ['android.attached', 'android.emulator', 'android.genycloud'], deviceAlias);313 case 'gpuMode':314 return this._unsupportedPropertyByDeviceType('gpuMode', ['android.emulator'], deviceAlias);315 case 'headless':316 return this._unsupportedPropertyByDeviceType('headless', ['android.emulator'], deviceAlias);317 case 'readonly':318 return this._unsupportedPropertyByDeviceType('readonly', ['android.emulator'], deviceAlias);319 case 'utilBinaryPaths':320 return this._unsupportedPropertyByDeviceType('utilBinaryPaths', ['android.attached', 'android.emulator', 'android.genycloud'], deviceAlias);321 default:322 throw new DetoxInternalError(`Composing .unsupportedDeviceProperty(${propertyName}) is not implemented`);323 }324 }325 missingDeviceMatcherProperties(deviceAlias, expectedProperties) {326 const { type } = this._resolveSelectedDeviceConfig(deviceAlias);327 return new DetoxConfigError({328 message: `Invalid or empty "device" matcher inside the device config.`,329 hint: `It should have the device query to run on, e.g.:\n330{331 "type": ${J(type)},332 "device": ${expectedProperties.map(p => `{ ${J(p)}: ... }`).join('\n // or ')}333}334Check that in your Detox config${this._atPath()}`,335 debugInfo: this._focusOnDeviceConfig(deviceAlias),336 inspectOptions: { depth: 4 },337 });338 }339 // endregion340 // region composeAppsConfig341 thereAreNoAppConfigs(appAlias) {342 return new DetoxConfigError({343 message: `Cannot use app alias ${J(appAlias)} since there is no "apps" config in Detox config${this._atPath()}`,344 hint: `\345You should create a dictionary of app configurations in Detox config, e.g.:346{347 "apps": {348*-> ${J(appAlias)}: {349| "type": "ios.app", // or "android.apk", or etc...350| "binaryPath": "path/to/your/app", // ... and so on351| }352| },353| "configurations": {354| ${J(this.configurationName)}: {355*---- "app": ${J(appAlias)},356 ...357 }358 }359}\n`,360 });361 }362 cantResolveAppAlias(appAlias) {363 return new DetoxConfigError({364 message: `Failed to find an app config ${J(appAlias)} in the "apps" dictionary of Detox config${this._atPath()}`,365 hint: 'Below are the app configurations Detox was able to find:\n' + hintList(this.contents.apps) +366 `\n\nCheck your configuration ${J(this.configurationName)}:`,367 debugInfo: this._getSelectedConfiguration(),368 inspectOptions: { depth: 1 },369 });370 }371 appConfigIsUndefined(appPath) {372 const appProperty = appPath[2] === 'apps'373 ? `"apps": [..., "myApp", ...]`374 : `"app": "myApp"`;375 return new DetoxConfigError({376 message: `Undefined or empty app config in the selected ${J(this.configurationName)} configuration:`,377 hint: `\378It should be an alias to an existing app config in "apps" dictionary, or the config object itself, e.g.:379{380 "apps": {381*-> "myApp": {382| "type": "ios.app", // or "android.apk", or etc...383| "binaryPath": "path/to/your/app", // ... and so on384| }385| },386| "configurations": {387| ${J(this.configurationName)}: {388*---- ${appProperty}389 ...390 }391 }392Examine your Detox config${this._atPath()}`,393 debugInfo: this._focusOnConfiguration(),394 inspectOptions: { depth: 2 }395 });396 }397 malformedAppLaunchArgs(appPath) {398 return new DetoxConfigError({399 message: `Invalid type of "launchArgs" property ${this._inTheAppConfig()}.\nExpected an object:`,400 debugInfo: this._focusOnAppConfig(appPath),401 inspectOptions: { depth: 4 },402 });403 }404 missingAppBinaryPath(appPath) {405 return new DetoxConfigError({406 message: `Missing "binaryPath" property ${this._inTheAppConfig()}.\nExpected a string:`,407 debugInfo: this._focusOnAppConfig(appPath, this._ensureProperty('binaryPath')),408 inspectOptions: { depth: 4 },409 });410 }411 invalidAppType({ appPath, allowedAppTypes, deviceType }) {412 return new DetoxConfigError({413 message: `Invalid app "type" property in the app config.\nExpected ${allowedAppTypes.map(J).join(' or ')}.`,414 hint: `\415You have a few options:4161. Replace the value with the suggestion.4172. Use a correct device type with this app config. Currently you have ${J(deviceType)}.`,418 debugInfo: this._focusOnAppConfig(appPath),419 inspectOptions: { depth: 4 },420 });421 }422 duplicateAppConfig({ appName, appPath, preExistingAppPath }) {423 const config1 = { ..._.get(this.contents, preExistingAppPath) };424 config1.name = config1.name || '<GIVE IT A NAME>';425 const config2 = { ..._.get(this.contents, appPath) };426 config2.name = '<GIVE IT ANOTHER NAME>';427 const name = this.configurationName;428 const hintMessage = appName429 ? `Both apps use the same name ${J(appName)} â try giving each app a unique name.`430 : `The app configs are missing "name" property that serves to distinct them.`;431 return new DetoxConfigError({432 message: `App collision detected in the selected configuration ${J(name)}.`,433 hint: `\434${hintMessage}435detox â ${preExistingAppPath.join(' â ')}:436${DetoxConfigError.inspectObj(config1, { depth: 0 })}437detox â ${appPath.join(' â ')}:438${DetoxConfigError.inspectObj(config2, { depth: 0 })}439Examine your Detox config${this._atPath()}`,440 });441 }442 noAppIsDefined(deviceType) {443 const name = this.configurationName;444 const [appType] = deviceAppTypes[deviceType] || [''];445 const [appPlatform] = appType.split('.');446 const appAlias = appType ? `myApp.${appPlatform}` : 'myApp';447 return new DetoxConfigError({448 message: `The ${J(name)} configuration has no defined "app" config.`,449 hint: `There should be an inlined object or an alias to the app config, e.g.:\n450{451 "apps": {452*-->"${appAlias}": {453| "type": "${appType || 'someAppType'}",454| "binaryPath": "path/to/app"455| },456| },457| "configurations": {458| ${J(name)}: {459*---- "app": "${appAlias}"460 ...461 }462 }463}464Examine your Detox config${this._atPath()}`,465 debugInfo: this._focusOnConfiguration(),466 inspectOptions: { depth: 0 }467 });468 }469 oldSchemaHasAppAndApps() {470 return new DetoxConfigError({471 message: `Your configuration ${J(this.configurationName)} appears to be in a legacy format, which canât contain "app" or "apps".`,472 hint: `Remove "type" property from configuration and use "device" property instead:\n` +473 `a) "device": { "type": ${J(this._getSelectedConfiguration().type)}, ... }\n` +474 `b) "device": "<alias-to-device>" // you should add that device configuration to "devices" with the same key` +475 `\n\nCheck your Detox config${this._atPath()}`,476 debugInfo: this._focusOnConfiguration(this._ensureProperty('type', 'device')),477 inspectOptions: { depth: 2 },478 });479 }480 ambiguousAppAndApps() {481 return new DetoxConfigError({482 message: `You can't have both "app" and "apps" defined in the ${J(this.configurationName)} configuration.`,483 hint: 'Use "app" if you have a single app to test.' +484 '\nUse "apps" if you have multiple apps to test.' +485 `\n\nCheck your Detox config${this._atPath()}`,486 debugInfo: this._focusOnConfiguration(this._ensureProperty('app', 'apps')),487 inspectOptions: { depth: 2 },...
Using AI Code Generation
1var oComponent = sap.ui.getCore().getComponent("rootComponent");2var oSelectedConfiguration = oComponent._getSelectedConfiguration();3oSelectedConfiguration["selectedLanguage"] = "EN";4oSelectedConfiguration["selectedTheme"] = "sap_bluecrystal";5oSelectedConfiguration["selectedSize"] = "Cozy";6oComponent._setSelectedConfiguration(oSelectedConfiguration);7![Configuration Dialog](
Using AI Code Generation
1var component = this.getComponent();2var selectedConfiguration = component._getSelectedConfiguration();3console.log(selectedConfiguration);4var component = this.getComponent();5var selectedConfiguration = component.getSelectedConfiguration();6console.log(selectedConfiguration);7var component = this.getComponent();8var selectedConfiguration = component.getSelectedConfiguration();9console.log(selectedConfiguration);10var component = this.getComponent();11var selectedConfiguration = component.getSelectedConfiguration();12console.log(selectedConfiguration);13var component = this.getComponent();14var selectedConfiguration = component.getSelectedConfiguration();15console.log(selectedConfiguration);16var component = this.getComponent();17var selectedConfiguration = component.getSelectedConfiguration();18console.log(selectedConfiguration);19var component = this.getComponent();20var selectedConfiguration = component.getSelectedConfiguration();21console.log(selectedConfiguration);22var component = this.getComponent();23var selectedConfiguration = component.getSelectedConfiguration();24console.log(selectedConfiguration);25var component = this.getComponent();26var selectedConfiguration = component.getSelectedConfiguration();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!