From 0a2b2202f311b6f9e67ef5ccd12feb02c6f4311a Mon Sep 17 00:00:00 2001 From: Canmert Date: Wed, 4 Oct 2023 18:49:26 +0300 Subject: [PATCH] fix(testing): e2e flag no longer needed, testID is now applicable in dev or prod builds (#10396) - you can now test on development or production with testID set - for android, this changes testID to use resource id instead of content description - you no longer need to pass `--env.e2e`. e2e is simply usable if testID is set - the `testID` property will also set `accessibilityIdentifier` and `accessibilityIdentifier` property will set `testID` only if there is a `testID` already set --- packages/core/accessibility/index.android.ts | 12 ++++--- packages/core/global-types.d.ts | 1 - packages/core/platforms/android/core.aar | Bin 1658 -> 1298 bytes packages/core/ui/core/view/index.android.ts | 30 ++++++------------ packages/core/ui/core/view/index.ios.ts | 19 +++++------ packages/core/ui/core/view/view-common.ts | 2 +- packages/core/ui/text-base/index.android.ts | 14 ++------ .../__snapshots__/angular.spec.ts.snap | 6 ++-- .../__snapshots__/base.spec.ts.snap | 6 ++-- .../__snapshots__/javascript.spec.ts.snap | 6 ++-- .../__snapshots__/react.spec.ts.snap | 4 --- .../__snapshots__/svelte.spec.ts.snap | 6 ++-- .../__snapshots__/typescript.spec.ts.snap | 6 ++-- .../__snapshots__/vue.spec.ts.snap | 6 ++-- packages/webpack5/src/configuration/base.ts | 3 -- packages/webpack5/src/index.ts | 1 - 16 files changed, 40 insertions(+), 82 deletions(-) diff --git a/packages/core/accessibility/index.android.ts b/packages/core/accessibility/index.android.ts index 41bb528c7..cadd85e99 100644 --- a/packages/core/accessibility/index.android.ts +++ b/packages/core/accessibility/index.android.ts @@ -1,6 +1,7 @@ import { Application, ApplicationEventData } from '../application'; import { Trace } from '../trace'; import { SDK_VERSION } from '../utils/constants'; +import { resources } from '../utils/android'; import type { View } from '../ui/core/view'; import { GestureTypes } from '../ui/gestures'; import { notifyAccessibilityFocusState } from './accessibility-common'; @@ -166,6 +167,12 @@ function ensureNativeClasses() { return; } + // Set resource id that can be used with test frameworks without polluting the content description. + const id = host.getTag(resources.getId(`:id/nativescript_accessibility_id`)); + if (id != null) { + info.setViewIdResourceName(id); + } + const accessibilityRole = view.accessibilityRole; if (accessibilityRole) { const androidClassName = RoleTypeMap.get(accessibilityRole); @@ -661,11 +668,6 @@ function applyContentDescription(view: View, forceUpdate?: boolean) { const contentDescription = contentDescriptionBuilder.join('. ').trim().replace(/^\.$/, ''); - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && view.testID) { - // ignore when testID is enabled - return; - } - if (contentDescription) { if (Trace.isEnabled()) { Trace.write(`${cls} - set to "${contentDescription}"`, Trace.categories.Accessibility); diff --git a/packages/core/global-types.d.ts b/packages/core/global-types.d.ts index 7eb160698..472744e04 100644 --- a/packages/core/global-types.d.ts +++ b/packages/core/global-types.d.ts @@ -131,7 +131,6 @@ declare const __CSS_PARSER__: string; declare const __NS_WEBPACK__: boolean; declare const __UI_USE_EXTERNAL_RENDERER__: boolean; declare const __UI_USE_XML_PARSER__: boolean; -declare const __USE_TEST_ID__: boolean | undefined; declare const __ANDROID__: boolean; declare const __IOS__: boolean; declare const __VISIONOS__: boolean; diff --git a/packages/core/platforms/android/core.aar b/packages/core/platforms/android/core.aar index ea938e613b1534ffe52ca6e3aee06b2465bf8bd9..1986e77700ee74c63556aa7a3c9b0664ef3e9ee4 100644 GIT binary patch delta 749 zcmeyxGl?rDz?+$ci-CcIgMop;k>Tst?N(YqmL?Fh0&$RDNkz%&GunYCd;(8+>zvf_ z*7egnrK8d5@8jpEt9Q=l)R~hyD|^^aNrgxhFfyPTwj|?rz+#{wKPL7`*Y_XfYBmsX zd0*#xW4Gth=}KAli!M}qT$9K#QKgq5*;RTOpOlLPrTy+?ZL+MoeK^D`Yig2l;su@lm{}52{5GFD@#@3^q1ltn zHkaLSKI1n@ug=x%=JHK*Q&Gg@TKMn2WqF8-Jcq!tfR7FPX_IEV91nF%Pr}43;#4C~!Im z@MdHZVMZhtc>Dqt2!jclKsKkJn8&&o_i#g-l$(pQ&Kr)t9K?W4A z=|Ck_KrD))bRpy90w(dvdsv0VVV-BOL{TyM4Qs0MTgQ7$3=Cz7Ii;z^`T^doY#=2Z NK=_>zn2wo2JOC^~`-T7j literal 1658 zcmbVM-A)rx5Z=-P1w;{%R0${=5`^w9NC2V!&_Ic0x7$*hm>5J4bitB^HoMD@7HIP-@O_%$7ry+G>S`;j*$%aC*8!W9GhDeN7YK+le0^lH7S^`3@^j??Ohbq0TmL zKkS8U83nrloaRnyb;N}0kTlG6GK1WKmp}L{ka&V3{Vu%1`Fmj>EYP!4(r{c zF`De#`#{CQcm_2x=RMSeZBkBKfd*i~5{_d!%CfK<;IwEifJ?r7z)q?nhA#xzrlST= zu%W3wB3T~XnNE}EEPya>omCs3h3+GLGS@!N~cmt$w@sKO-{5zXL49j zIf0Um#+P@4A!zMDd9wpEzn(YG*x8^xg-#0Q^3C(^2FtIMLM`+|DGpS%1poD9kUM<{ z4v5y@yroGB$o9sqKnkKI$yj(HON!HzHdy*QOnodM5P@P{Dd!xw;^n`j;JEL^GB zPx7G)aoA_Q>{C8HzbkLge?j&`@F=)9$ib!YhdWw<-cT`Y?Z0c%KN*GIKPoB^{`jb{ UW(-v}U0p+iVf?(A>L9iM0_#nJl>h($ diff --git a/packages/core/ui/core/view/index.android.ts b/packages/core/ui/core/view/index.android.ts index 04fbf6938..f6e67654f 100644 --- a/packages/core/ui/core/view/index.android.ts +++ b/packages/core/ui/core/view/index.android.ts @@ -794,20 +794,19 @@ export class View extends ViewCommon { } [testIDProperty.setNative](value: string) { - this.setTestID(this.nativeViewProtected, value); + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } - setTestID(view, value) { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) { - const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id'); + setAccessibilityIdentifier(view, value) { + const id = Utils.android.resources.getId(':id/nativescript_accessibility_id'); - if (id) { - view.setTag(id, value); - view.setTag(value); - } - - view.setContentDescription(value); + if (id) { + view.setTag(id, value); + view.setTag(value); } + + if (this.testID && this.testID !== value) this.testID = value; + if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value; } [accessibilityEnabledProperty.setNative](value: boolean): void { @@ -817,16 +816,7 @@ export class View extends ViewCommon { } [accessibilityIdentifierProperty.setNative](value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) { - // ignore when using testID; - } else { - const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id'); - - if (id) { - this.nativeViewProtected.setTag(id, value); - this.nativeViewProtected.setTag(value); - } - } + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } [accessibilityRoleProperty.setNative](value: AccessibilityRole): void { diff --git a/packages/core/ui/core/view/index.ios.ts b/packages/core/ui/core/view/index.ios.ts index 9fa8b0442..3967b3b69 100644 --- a/packages/core/ui/core/view/index.ios.ts +++ b/packages/core/ui/core/view/index.ios.ts @@ -679,13 +679,14 @@ export class View extends ViewCommon implements ViewDefinition { } [testIDProperty.setNative](value: string) { - this.setTestID(this.nativeViewProtected, value); + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } - public setTestID(view: any, value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) { - view.accessibilityIdentifier = value; - } + public setAccessibilityIdentifier(view: any, value: string): void { + view.accessibilityIdentifier = value; + + if (this.testID && this.testID !== value) this.testID = value; + if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value; } [accessibilityEnabledProperty.setNative](value: boolean): void { @@ -695,15 +696,11 @@ export class View extends ViewCommon implements ViewDefinition { } [accessibilityIdentifierProperty.getDefault](): string { - return this.nativeViewProtected.accessibilityLabel; + return this.nativeViewProtected.accessibilityIdentifier; } [accessibilityIdentifierProperty.setNative](value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) { - // ignore when using testID - } else { - this.nativeViewProtected.accessibilityIdentifier = value; - } + this.setAccessibilityIdentifier(this.nativeViewProtected, value); } [accessibilityRoleProperty.setNative](value: AccessibilityRole): void { diff --git a/packages/core/ui/core/view/view-common.ts b/packages/core/ui/core/view/view-common.ts index 58adce944..ad3e3cf26 100644 --- a/packages/core/ui/core/view/view-common.ts +++ b/packages/core/ui/core/view/view-common.ts @@ -1173,7 +1173,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { return; } - public setTestID(view: any, value: string) { + public setAccessibilityIdentifier(view: any, value: string) { return; } } diff --git a/packages/core/ui/text-base/index.android.ts b/packages/core/ui/text-base/index.android.ts index 25ddad5cf..37be9f247 100644 --- a/packages/core/ui/text-base/index.android.ts +++ b/packages/core/ui/text-base/index.android.ts @@ -465,21 +465,11 @@ export class TextBase extends TextBaseCommon { } [testIDProperty.setNative](value: string): void { - this.setTestID(this.nativeTextViewProtected, value); + this.setAccessibilityIdentifier(this.nativeTextViewProtected, value); } [accessibilityIdentifierProperty.setNative](value: string): void { - if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) { - // ignore when using testID; - } else { - // we override the default setter to apply it on nativeTextViewProtected - const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id'); - - if (id) { - this.nativeTextViewProtected.setTag(id, value); - this.nativeTextViewProtected.setTag(value); - } - } + this.setAccessibilityIdentifier(this.nativeTextViewProtected, value); } [maxLinesProperty.setNative](value: number) { diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap index 209c654fe..0ce7972bc 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap @@ -367,8 +367,7 @@ exports[`angular configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -800,8 +799,7 @@ exports[`angular configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap index bdb96879f..9b3fd6325 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap @@ -269,8 +269,7 @@ exports[`base configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -597,8 +596,7 @@ exports[`base configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap index 5341c1e17..9ee90ab55 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap @@ -269,8 +269,7 @@ exports[`javascript configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -596,8 +595,7 @@ exports[`javascript configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap index 1fdd9b35b..abe3c8c59 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap @@ -292,7 +292,6 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR 'global.isIOS': false, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } @@ -631,7 +630,6 @@ exports[`react configuration > android > base config 1`] = ` 'global.isIOS': false, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } @@ -977,7 +975,6 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena 'global.isIOS': true, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } @@ -1317,7 +1314,6 @@ exports[`react configuration > ios > base config 1`] = ` 'global.isIOS': true, 'global.isVisionOS': false, process: 'global.process', - __USE_TEST_ID__: false, __TEST__: false, 'process.env.NODE_ENV': '"development"' } diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap index 1fd6be11a..98a774cff 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap @@ -296,8 +296,7 @@ exports[`svelte configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -645,8 +644,7 @@ exports[`svelte configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap index 46b6beeef..811bfe377 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap @@ -269,8 +269,7 @@ exports[`typescript configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -596,8 +595,7 @@ exports[`typescript configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap index 9d756f755..3d708a2ae 100644 --- a/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap +++ b/packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap @@ -309,8 +309,7 @@ exports[`vue configuration for android 1`] = ` 'global.isAndroid': true, 'global.isIOS': false, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ @@ -671,8 +670,7 @@ exports[`vue configuration for ios 1`] = ` 'global.isAndroid': false, 'global.isIOS': true, 'global.isVisionOS': false, - process: 'global.process', - __USE_TEST_ID__: false + process: 'global.process' } ), /* config.plugin('CopyWebpackPlugin') */ diff --git a/packages/webpack5/src/configuration/base.ts b/packages/webpack5/src/configuration/base.ts index 16472530f..00291c9de 100644 --- a/packages/webpack5/src/configuration/base.ts +++ b/packages/webpack5/src/configuration/base.ts @@ -449,9 +449,6 @@ export default function (config: Config, env: IWebpackEnv = _env): Config { /* for compat only */ 'global.isVisionOS': platform === 'visionos', process: 'global.process', - // enable testID when using --env.e2e - __USE_TEST_ID__: !!env.e2e, - // todo: ?!?! // profile: '() => {}', }, diff --git a/packages/webpack5/src/index.ts b/packages/webpack5/src/index.ts index 058c74b68..f9ac6f073 100644 --- a/packages/webpack5/src/index.ts +++ b/packages/webpack5/src/index.ts @@ -52,7 +52,6 @@ export interface IWebpackEnv { // misc replace?: string[] | string; watchNodeModules?: boolean; - e2e?: boolean; } interface IChainEntry {