mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 10:01:08 +08:00
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
This commit is contained in:
@ -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);
|
||||
|
1
packages/core/global-types.d.ts
vendored
1
packages/core/global-types.d.ts
vendored
@ -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;
|
||||
|
Binary file not shown.
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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') */
|
||||
|
@ -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') */
|
||||
|
@ -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') */
|
||||
|
@ -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"'
|
||||
}
|
||||
|
@ -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') */
|
||||
|
@ -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') */
|
||||
|
@ -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') */
|
||||
|
@ -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: '() => {}',
|
||||
},
|
||||
|
@ -52,7 +52,6 @@ export interface IWebpackEnv {
|
||||
// misc
|
||||
replace?: string[] | string;
|
||||
watchNodeModules?: boolean;
|
||||
e2e?: boolean;
|
||||
}
|
||||
|
||||
interface IChainEntry {
|
||||
|
Reference in New Issue
Block a user