Skip to content

Commit 0a2b220

Browse files
authored
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
1 parent 757af14 commit 0a2b220

File tree

16 files changed

+40
-82
lines changed

16 files changed

+40
-82
lines changed

packages/core/accessibility/index.android.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Application, ApplicationEventData } from '../application';
22
import { Trace } from '../trace';
33
import { SDK_VERSION } from '../utils/constants';
4+
import { resources } from '../utils/android';
45
import type { View } from '../ui/core/view';
56
import { GestureTypes } from '../ui/gestures';
67
import { notifyAccessibilityFocusState } from './accessibility-common';
@@ -166,6 +167,12 @@ function ensureNativeClasses() {
166167
return;
167168
}
168169

170+
// Set resource id that can be used with test frameworks without polluting the content description.
171+
const id = host.getTag(resources.getId(`:id/nativescript_accessibility_id`));
172+
if (id != null) {
173+
info.setViewIdResourceName(id);
174+
}
175+
169176
const accessibilityRole = view.accessibilityRole;
170177
if (accessibilityRole) {
171178
const androidClassName = RoleTypeMap.get(accessibilityRole);
@@ -661,11 +668,6 @@ function applyContentDescription(view: View, forceUpdate?: boolean) {
661668

662669
const contentDescription = contentDescriptionBuilder.join('. ').trim().replace(/^\.$/, '');
663670

664-
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && view.testID) {
665-
// ignore when testID is enabled
666-
return;
667-
}
668-
669671
if (contentDescription) {
670672
if (Trace.isEnabled()) {
671673
Trace.write(`${cls} - set to "${contentDescription}"`, Trace.categories.Accessibility);

packages/core/global-types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ declare const __CSS_PARSER__: string;
131131
declare const __NS_WEBPACK__: boolean;
132132
declare const __UI_USE_EXTERNAL_RENDERER__: boolean;
133133
declare const __UI_USE_XML_PARSER__: boolean;
134-
declare const __USE_TEST_ID__: boolean | undefined;
135134
declare const __ANDROID__: boolean;
136135
declare const __IOS__: boolean;
137136
declare const __VISIONOS__: boolean;
-360 Bytes
Binary file not shown.

packages/core/ui/core/view/index.android.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -794,20 +794,19 @@ export class View extends ViewCommon {
794794
}
795795

796796
[testIDProperty.setNative](value: string) {
797-
this.setTestID(this.nativeViewProtected, value);
797+
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
798798
}
799799

800-
setTestID(view, value) {
801-
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) {
802-
const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id');
800+
setAccessibilityIdentifier(view, value) {
801+
const id = Utils.android.resources.getId(':id/nativescript_accessibility_id');
803802

804-
if (id) {
805-
view.setTag(id, value);
806-
view.setTag(value);
807-
}
808-
809-
view.setContentDescription(value);
803+
if (id) {
804+
view.setTag(id, value);
805+
view.setTag(value);
810806
}
807+
808+
if (this.testID && this.testID !== value) this.testID = value;
809+
if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value;
811810
}
812811

813812
[accessibilityEnabledProperty.setNative](value: boolean): void {
@@ -817,16 +816,7 @@ export class View extends ViewCommon {
817816
}
818817

819818
[accessibilityIdentifierProperty.setNative](value: string): void {
820-
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) {
821-
// ignore when using testID;
822-
} else {
823-
const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id');
824-
825-
if (id) {
826-
this.nativeViewProtected.setTag(id, value);
827-
this.nativeViewProtected.setTag(value);
828-
}
829-
}
819+
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
830820
}
831821

832822
[accessibilityRoleProperty.setNative](value: AccessibilityRole): void {

packages/core/ui/core/view/index.ios.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,14 @@ export class View extends ViewCommon implements ViewDefinition {
679679
}
680680

681681
[testIDProperty.setNative](value: string) {
682-
this.setTestID(this.nativeViewProtected, value);
682+
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
683683
}
684684

685-
public setTestID(view: any, value: string): void {
686-
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__) {
687-
view.accessibilityIdentifier = value;
688-
}
685+
public setAccessibilityIdentifier(view: any, value: string): void {
686+
view.accessibilityIdentifier = value;
687+
688+
if (this.testID && this.testID !== value) this.testID = value;
689+
if (this.accessibilityIdentifier !== value) this.accessibilityIdentifier = value;
689690
}
690691

691692
[accessibilityEnabledProperty.setNative](value: boolean): void {
@@ -695,15 +696,11 @@ export class View extends ViewCommon implements ViewDefinition {
695696
}
696697

697698
[accessibilityIdentifierProperty.getDefault](): string {
698-
return this.nativeViewProtected.accessibilityLabel;
699+
return this.nativeViewProtected.accessibilityIdentifier;
699700
}
700701

701702
[accessibilityIdentifierProperty.setNative](value: string): void {
702-
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) {
703-
// ignore when using testID
704-
} else {
705-
this.nativeViewProtected.accessibilityIdentifier = value;
706-
}
703+
this.setAccessibilityIdentifier(this.nativeViewProtected, value);
707704
}
708705

709706
[accessibilityRoleProperty.setNative](value: AccessibilityRole): void {

packages/core/ui/core/view/view-common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
11731173
return;
11741174
}
11751175

1176-
public setTestID(view: any, value: string) {
1176+
public setAccessibilityIdentifier(view: any, value: string) {
11771177
return;
11781178
}
11791179
}

packages/core/ui/text-base/index.android.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -465,21 +465,11 @@ export class TextBase extends TextBaseCommon {
465465
}
466466

467467
[testIDProperty.setNative](value: string): void {
468-
this.setTestID(this.nativeTextViewProtected, value);
468+
this.setAccessibilityIdentifier(this.nativeTextViewProtected, value);
469469
}
470470

471471
[accessibilityIdentifierProperty.setNative](value: string): void {
472-
if (typeof __USE_TEST_ID__ !== 'undefined' && __USE_TEST_ID__ && this.testID) {
473-
// ignore when using testID;
474-
} else {
475-
// we override the default setter to apply it on nativeTextViewProtected
476-
const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id');
477-
478-
if (id) {
479-
this.nativeTextViewProtected.setTag(id, value);
480-
this.nativeTextViewProtected.setTag(value);
481-
}
482-
}
472+
this.setAccessibilityIdentifier(this.nativeTextViewProtected, value);
483473
}
484474

485475
[maxLinesProperty.setNative](value: number) {

packages/webpack5/__tests__/configuration/__snapshots__/angular.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ exports[`angular configuration for android 1`] = `
367367
'global.isAndroid': true,
368368
'global.isIOS': false,
369369
'global.isVisionOS': false,
370-
process: 'global.process',
371-
__USE_TEST_ID__: false
370+
process: 'global.process'
372371
}
373372
),
374373
/* config.plugin('CopyWebpackPlugin') */
@@ -800,8 +799,7 @@ exports[`angular configuration for ios 1`] = `
800799
'global.isAndroid': false,
801800
'global.isIOS': true,
802801
'global.isVisionOS': false,
803-
process: 'global.process',
804-
__USE_TEST_ID__: false
802+
process: 'global.process'
805803
}
806804
),
807805
/* config.plugin('CopyWebpackPlugin') */

packages/webpack5/__tests__/configuration/__snapshots__/base.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ exports[`base configuration for android 1`] = `
269269
'global.isAndroid': true,
270270
'global.isIOS': false,
271271
'global.isVisionOS': false,
272-
process: 'global.process',
273-
__USE_TEST_ID__: false
272+
process: 'global.process'
274273
}
275274
),
276275
/* config.plugin('CopyWebpackPlugin') */
@@ -597,8 +596,7 @@ exports[`base configuration for ios 1`] = `
597596
'global.isAndroid': false,
598597
'global.isIOS': true,
599598
'global.isVisionOS': false,
600-
process: 'global.process',
601-
__USE_TEST_ID__: false
599+
process: 'global.process'
602600
}
603601
),
604602
/* config.plugin('CopyWebpackPlugin') */

packages/webpack5/__tests__/configuration/__snapshots__/javascript.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ exports[`javascript configuration for android 1`] = `
269269
'global.isAndroid': true,
270270
'global.isIOS': false,
271271
'global.isVisionOS': false,
272-
process: 'global.process',
273-
__USE_TEST_ID__: false
272+
process: 'global.process'
274273
}
275274
),
276275
/* config.plugin('CopyWebpackPlugin') */
@@ -596,8 +595,7 @@ exports[`javascript configuration for ios 1`] = `
596595
'global.isAndroid': false,
597596
'global.isIOS': true,
598597
'global.isVisionOS': false,
599-
process: 'global.process',
600-
__USE_TEST_ID__: false
598+
process: 'global.process'
601599
}
602600
),
603601
/* config.plugin('CopyWebpackPlugin') */

packages/webpack5/__tests__/configuration/__snapshots__/react.spec.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ exports[`react configuration > android > adds ReactRefreshWebpackPlugin when HMR
292292
'global.isIOS': false,
293293
'global.isVisionOS': false,
294294
process: 'global.process',
295-
__USE_TEST_ID__: false,
296295
__TEST__: false,
297296
'process.env.NODE_ENV': '"development"'
298297
}
@@ -631,7 +630,6 @@ exports[`react configuration > android > base config 1`] = `
631630
'global.isIOS': false,
632631
'global.isVisionOS': false,
633632
process: 'global.process',
634-
__USE_TEST_ID__: false,
635633
__TEST__: false,
636634
'process.env.NODE_ENV': '"development"'
637635
}
@@ -977,7 +975,6 @@ exports[`react configuration > ios > adds ReactRefreshWebpackPlugin when HMR ena
977975
'global.isIOS': true,
978976
'global.isVisionOS': false,
979977
process: 'global.process',
980-
__USE_TEST_ID__: false,
981978
__TEST__: false,
982979
'process.env.NODE_ENV': '"development"'
983980
}
@@ -1317,7 +1314,6 @@ exports[`react configuration > ios > base config 1`] = `
13171314
'global.isIOS': true,
13181315
'global.isVisionOS': false,
13191316
process: 'global.process',
1320-
__USE_TEST_ID__: false,
13211317
__TEST__: false,
13221318
'process.env.NODE_ENV': '"development"'
13231319
}

packages/webpack5/__tests__/configuration/__snapshots__/svelte.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ exports[`svelte configuration for android 1`] = `
296296
'global.isAndroid': true,
297297
'global.isIOS': false,
298298
'global.isVisionOS': false,
299-
process: 'global.process',
300-
__USE_TEST_ID__: false
299+
process: 'global.process'
301300
}
302301
),
303302
/* config.plugin('CopyWebpackPlugin') */
@@ -645,8 +644,7 @@ exports[`svelte configuration for ios 1`] = `
645644
'global.isAndroid': false,
646645
'global.isIOS': true,
647646
'global.isVisionOS': false,
648-
process: 'global.process',
649-
__USE_TEST_ID__: false
647+
process: 'global.process'
650648
}
651649
),
652650
/* config.plugin('CopyWebpackPlugin') */

packages/webpack5/__tests__/configuration/__snapshots__/typescript.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ exports[`typescript configuration for android 1`] = `
269269
'global.isAndroid': true,
270270
'global.isIOS': false,
271271
'global.isVisionOS': false,
272-
process: 'global.process',
273-
__USE_TEST_ID__: false
272+
process: 'global.process'
274273
}
275274
),
276275
/* config.plugin('CopyWebpackPlugin') */
@@ -596,8 +595,7 @@ exports[`typescript configuration for ios 1`] = `
596595
'global.isAndroid': false,
597596
'global.isIOS': true,
598597
'global.isVisionOS': false,
599-
process: 'global.process',
600-
__USE_TEST_ID__: false
598+
process: 'global.process'
601599
}
602600
),
603601
/* config.plugin('CopyWebpackPlugin') */

packages/webpack5/__tests__/configuration/__snapshots__/vue.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ exports[`vue configuration for android 1`] = `
309309
'global.isAndroid': true,
310310
'global.isIOS': false,
311311
'global.isVisionOS': false,
312-
process: 'global.process',
313-
__USE_TEST_ID__: false
312+
process: 'global.process'
314313
}
315314
),
316315
/* config.plugin('CopyWebpackPlugin') */
@@ -671,8 +670,7 @@ exports[`vue configuration for ios 1`] = `
671670
'global.isAndroid': false,
672671
'global.isIOS': true,
673672
'global.isVisionOS': false,
674-
process: 'global.process',
675-
__USE_TEST_ID__: false
673+
process: 'global.process'
676674
}
677675
),
678676
/* config.plugin('CopyWebpackPlugin') */

packages/webpack5/src/configuration/base.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,6 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
449449
/* for compat only */ 'global.isVisionOS': platform === 'visionos',
450450
process: 'global.process',
451451

452-
// enable testID when using --env.e2e
453-
__USE_TEST_ID__: !!env.e2e,
454-
455452
// todo: ?!?!
456453
// profile: '() => {}',
457454
},

packages/webpack5/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export interface IWebpackEnv {
5252
// misc
5353
replace?: string[] | string;
5454
watchNodeModules?: boolean;
55-
e2e?: boolean;
5655
}
5756

5857
interface IChainEntry {

0 commit comments

Comments
 (0)