Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mobile] - Remove unused pre/post bundle commands #58305

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/rnmobile-ios-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
key: ${{ runner.os }}-tests-setup-${{ hashFiles('package-lock.json') }}

- name: Prepare tests setup
run: npm run native test:e2e:setup
run: TEST_ENV=github npm run native test:e2e:setup

- name: Prepare build cache key
run: find package-lock.json packages/react-native-editor/ios packages/react-native-aztec/ios packages/react-native-bridge/ios -type f -print0 | sort -z | xargs -0 shasum | tee ios-checksums.txt
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
run: test -d packages/react-native-editor/ios/build/WDA || npm run native test:e2e:build-wda

- name: Run iOS Device Tests
run: TEST_RN_PLATFORM=ios npm run native device-tests:local ${{ matrix.native-test-name }}
run: TEST_ENV=github TEST_RN_PLATFORM=ios npm run native device-tests:local ${{ matrix.native-test-name }}

- name: Prepare build cache
run: |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
"other:check-local-changes": "node ./bin/check-local-changes.js",
"other:cherry-pick": "node ./bin/cherry-pick.mjs",
"other:update-packages:php": "wp-env run --env-cwd='wp-content/plugins/gutenberg' cli composer update --no-interaction",
"postinstall": "patch-package && node ./patches/patch-xcode.js",
"postinstall": "patch-package",
"prepare": "husky install",
"prepublishOnly": "npm run clean:package-types && npm run build:packages",
"start": "npm run dev",
Expand Down
5 changes: 4 additions & 1 deletion packages/react-native-aztec/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Project-wide Gradle settings.

org.gradle.jvmargs=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError
org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true

# React Native Aztec properties.

Expand Down
5 changes: 4 additions & 1 deletion packages/react-native-bridge/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Project-wide Gradle settings.

org.gradle.jvmargs=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError
org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true

# React Native Bridge properties.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ onlyOniOS( 'Gutenberg Editor Cover Block test', () => {
// Height is set to 20rem, where 1rem is 16.
// There is also block's vertical padding equal 16.
// Finally, the total height should be 20 * 16 + 16 = 336.
expect( height ).toBe( 336 );
// Since different simulators may have slight variations, we allow a range of values.
expect( height ).toBeGreaterThanOrEqual( 336 );
expect( height ).toBeLessThanOrEqual( 337 );

await coverBlock.click();
expect( coverBlock ).toBeTruthy();
Expand Down
38 changes: 16 additions & 22 deletions packages/react-native-editor/__device-tests__/helpers/caps.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,24 @@ const ios = {
args: [ 'uitesting' ],
},
autoLaunch: false,
simulatorStartupTimeout: 240,
reduceMotion: true,
maxTypingFrequency: 30,
};

exports.iosLocal = ( { iPadDevice = false } ) => ( {
...ios,
deviceName: ! iPadDevice
? iOSConfig.local.deviceName
: iOSConfig.local.deviceTabletName,
platformVersion: iOSConfig.local.platformVersion,
pixelRatio: ! iPadDevice
? iOSConfig.pixelRatio.iPhone
: iOSConfig.pixelRatio.iPad,
usePrebuiltWDA: true,
} );

exports.iosServer = ( { iPadDevice = false } ) => ( {
...ios,
deviceName: ! iPadDevice
? iOSConfig.saucelabs.deviceName
: iOSConfig.saucelabs.deviceTabletName,
platformVersion: iOSConfig.local.platformVersion,
pixelRatio: ! iPadDevice
? iOSConfig.pixelRatio.iPhone
: iOSConfig.pixelRatio.iPad,
} );
exports.iosLocal = ( { iPadDevice = false, environment } ) => {
return {
...ios,
deviceName: ! iPadDevice
? iOSConfig[ environment ].deviceName
: iOSConfig[ environment ].deviceTabletName,
platformVersion: iOSConfig[ environment ].platformVersion,
pixelRatio: ! iPadDevice
? iOSConfig.pixelRatio.iPhone
: iOSConfig.pixelRatio.iPad,
usePrebuiltWDA: true,
};
};

exports.android = {
platformVersion: androidConfig.local.platformVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"ios": {
"local": {
"deviceName": "iPhone 15",
"deviceTabletName": "iPad (10th generation)",
"platformVersion": "17.0"
},
"github": {
"deviceName": "iPhone 14",
"deviceTabletName": "iPad (10th generation)",
"platformVersion": "16.2"
},
"saucelabs": {
"deviceName": "iPhone 14 Simulator",
"deviceTabletName": "iPad (10th generation) Simulator"
},
"buildkite": {
"platformVersion": "16.4"
},
"pixelRatio": {
"iPhone": 3,
"iPad": 2
Expand Down
110 changes: 58 additions & 52 deletions packages/react-native-editor/__device-tests__/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const path = require( 'path' );
*/
const serverConfigs = require( './serverConfigs' );
const {
iosServer,
iosLocal,
android,
sauceOptions,
Expand Down Expand Up @@ -126,38 +125,38 @@ const setupDriver = async () => {
desiredCaps.newCommandTimeout = SAUCE_LABS_TIMEOUT;
}
} else {
desiredCaps = iosServer( { iPadDevice } );
desiredCaps = desiredCaps = iosLocal( {
iPadDevice,
environment: testEnvironment,
} );
desiredCaps.newCommandTimeout = SAUCE_LABS_TIMEOUT;
desiredCaps.app = `storage:filename=Gutenberg-${ safeBranchName }.app.zip`; // App should be preloaded to sauce storage, this can also be a URL.
if ( isLocalEnvironment() ) {
desiredCaps = iosLocal( { iPadDevice } );

const iosPlatformVersions = getIOSPlatformVersions( {
requiredVersion: desiredCaps.platformVersion,
} );
if ( iosPlatformVersions.length === 0 ) {
throw new Error(
`No compatible iOS simulators available! Please verify that you have iOS ${ desiredCaps.platformVersion } simulators installed.`
);
}
// eslint-disable-next-line no-console
console.log(
'Available iOS platform versions:',
iosPlatformVersions.map( ( { name } ) => name )
const iosPlatformVersions = getIOSPlatformVersions( {
requiredVersion: desiredCaps.platformVersion,
} );
if ( iosPlatformVersions.length === 0 ) {
throw new Error(
`No compatible iOS simulators available! Please verify that you have iOS ${ desiredCaps.platformVersion } simulators installed.`
);
}
// eslint-disable-next-line no-console
console.log(
'Available iOS platform versions:',
iosPlatformVersions.map( ( { name } ) => name )
);

if ( ! desiredCaps.platformVersion ) {
desiredCaps.platformVersion = iosPlatformVersions[ 0 ].version;

// eslint-disable-next-line no-console
console.log(
`Using iOS ${ desiredCaps.platformVersion } platform version`
);
}
if ( ! desiredCaps.platformVersion ) {
desiredCaps.platformVersion = iosPlatformVersions[ 0 ].version;

desiredCaps.app = path.resolve( localIOSAppPath );
desiredCaps.derivedDataPath = path.resolve( webDriverAgentPath );
// eslint-disable-next-line no-console
console.log(
`Using iOS ${ desiredCaps.platformVersion } platform version`
);
}

desiredCaps.app = path.resolve( localIOSAppPath );
desiredCaps.derivedDataPath = path.resolve( webDriverAgentPath );
}

const sauceOptionsConfig = ! isLocalEnvironment()
Expand Down Expand Up @@ -224,11 +223,6 @@ const typeString = async ( driver, element, str, clear ) => {
}

await element.addValue( str );

if ( ! isAndroid() ) {
// Await the completion of the scroll-to-text-input animation
await driver.pause( 3000 );
}
};

/**
Expand Down Expand Up @@ -296,11 +290,15 @@ const clickMiddleOfElement = async ( driver, element ) => {
// Clicks in the top left of an element.
const clickBeginningOfElement = async ( driver, element ) => {
const location = await element.getLocation();
const borderPadding = 8;
await driver
.action( 'pointer', {
parameters: { pointerType: 'touch' },
} )
.move( { x: location.x, y: location.y } )
.move( {
x: location.x + borderPadding,
y: location.y + borderPadding,
} )
.down()
.up()
.perform();
Expand Down Expand Up @@ -408,13 +406,28 @@ const selectTextFromElement = async ( driver, element ) => {
.perform();
} else {
// On iOS we can use the context menu to "Select all" text.
await longPressMiddleOfElement( driver, element );

const selectAllElement = await driver.$(
'//XCUIElementTypeMenuItem[@name="Select All"]'
await clickBeginningOfElement( driver, element );

const selectAllSelector =
'//XCUIElementTypeMenuItem[@name="Select All"]';
const selectCopySelector = '//XCUIElementTypeMenuItem[@name="Copy"]';

// Wait for the context menu to be opened, there are cases where it selects the
// text automatticaly so the context option will be different.
await driver.waitUntil(
async function () {
return (
( await driver.$( selectAllSelector ).isDisplayed() ) ||
( await driver.$( selectCopySelector ).isDisplayed() )
);
},
{ timeout: 8000 }
);
await selectAllElement.waitForDisplayed( { timeout } );
await selectAllElement.click();

const selectAllElement = await driver.$$( selectAllSelector );
if ( selectAllElement.length > 0 ) {
await selectAllElement[ 0 ].click();
}
}
};

Expand Down Expand Up @@ -536,23 +549,16 @@ const toggleHtmlMode = async ( driver, toggleOn ) => {
'/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView/android.widget.TextView[9]';

await clickIfClickable( driver, showHtmlButtonXpath );
} else if ( toggleOn ) {
const moreOptionsButton = await driver.$( '~editor-menu-button' );
await moreOptionsButton.click();

await clickIfClickable(
driver,
'//XCUIElementTypeButton[@name="Switch to HTML"]'
);
} else {
// This is to wait for the clipboard paste notification to disappear, currently it overlaps with the menu button
await driver.pause( 3000 );
const action = toggleOn ? 'Switch to HTML' : 'Switch To Visual';
await driver.waitUntil( driver.$( '~editor-menu-button' ).isDisplayed );
const moreOptionsButton = await driver.$( '~editor-menu-button' );
await moreOptionsButton.click();
await clickIfClickable(
driver,
'//XCUIElementTypeButton[@name="Switch To Visual"]'
);

await driver.waitUntil( driver.$( `~${ action }` ).isDisplayed );

const actionButton = await driver.$( `~${ action }` );
await actionButton.click();
}
};

Expand Down
3 changes: 3 additions & 0 deletions packages/react-native-editor/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx6g -XX:+HeapDumpOnOutOfMemoryError
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.caching=true

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-editor/bin/build-e2e-wda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ CONFIG_FILE="$(pwd)/__device-tests__/helpers/device-config.json"
IOS_DEVICE_NAME=$(jq -r '.ios.local.deviceName' "$CONFIG_FILE")
IOS_PLATFORM_VERSION=$(jq -r '.ios.local.platformVersion' "$CONFIG_FILE")

xcodebuild -project ~/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "platform=iOS Simulator,name=$IOS_DEVICE_NAME,OS=$IOS_PLATFORM_VERSION" -derivedDataPath ios/build/WDA
xcodebuild -project ~/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "platform=iOS Simulator,name=$IOS_DEVICE_NAME" -derivedDataPath ios/build/WDA
2 changes: 1 addition & 1 deletion packages/react-native-editor/bin/build_e2e_ios_app
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CONFIG_FILE="$(pwd)/__device-tests__/helpers/device-config.json"
IOS_DEVICE_NAME=$(jq -r '.ios.local.deviceName' "$CONFIG_FILE")
IOS_PLATFORM_VERSION=$(jq -r '.ios.local.platformVersion' "$CONFIG_FILE")

DEFAULT_DESTINATION="platform=iOS Simulator,name=$IOS_DEVICE_NAME,OS=$IOS_PLATFORM_VERSION"
DEFAULT_DESTINATION="platform=iOS Simulator,name=$IOS_DEVICE_NAME"
if [[ -z "${RN_EDITOR_E2E_IOS_DESTINATION-}" ]]; then
DESTINATION="$DEFAULT_DESTINATION"
else
Expand Down
7 changes: 4 additions & 3 deletions packages/react-native-editor/bin/test-e2e-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function log_error() {
printf "❌ $1\n"
}

TEST_ENV=${TEST_ENV:-"local"}
output=$($APPIUM_CMD driver list --installed --json)

if echo "$output" | grep -q 'uiautomator2'; then
Expand All @@ -38,7 +39,7 @@ else
fi

CONFIG_FILE="$(pwd)/__device-tests__/helpers/device-config.json"
IOS_PLATFORM_VERSION=$(jq -r '.ios.local.platformVersion' "$CONFIG_FILE")
IOS_PLATFORM_VERSION=$(jq -r ".ios.$TEST_ENV.platformVersion" "$CONFIG_FILE")

# Throw an error if the required iOS runtime is not installed
IOS_RUNTIME_INSTALLED=$(xcrun simctl list runtimes -j | jq -r --arg version "$IOS_PLATFORM_VERSION" '.runtimes | to_entries[] | select(.value.version | contains($version))')
Expand All @@ -62,8 +63,8 @@ function detect_or_create_simulator() {
fi
}

IOS_DEVICE_NAME=$(jq -r '.ios.local.deviceName' "$CONFIG_FILE")
IOS_DEVICE_TABLET_NAME=$(jq -r '.ios.local.deviceTabletName' "$CONFIG_FILE")
IOS_DEVICE_NAME=$(jq -r ".ios.$TEST_ENV.deviceName" "$CONFIG_FILE")
IOS_DEVICE_TABLET_NAME=$(jq -r ".ios.$TEST_ENV.deviceTabletName" "$CONFIG_FILE")

# Create the required iOS simulators, if they don't exist
detect_or_create_simulator "$IOS_DEVICE_NAME"
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@
"start:debug": "node --inspect-brk node_modules/.bin/react-native start",
"start:reset": "npm run clean:runtime && npm run start:quick -- --reset-cache",
"start:quick": "react-native start",
"prern-bundle": "cd ../.. && patch-package --patch-dir packages/react-native-editor/metro-patch",
"rn-bundle": "react-native bundle",
"postrn-bundle": "cd ../.. && patch-package --reverse --patch-dir packages/react-native-editor/metro-patch",
"prebundle": "npm run i18n-cache:force",
"bundle": "npm run bundle:android && npm run bundle:ios",
"bundle:android": "mkdir -p bundle/android && npm run rn-bundle -- --platform android --dev false --entry-file index.js --assets-dest bundle/android --bundle-output bundle/android/App.text.js --sourcemap-output bundle/android/App.text.js.map && ./../../node_modules/react-native/sdks/hermesc/`node -e \"const platform=require('os').platform();console.log(platform === 'darwin' ? 'osx-bin' : (platform === 'linux' ? 'linux64-bin' : (platform === 'win32' ? 'win64-bin' : 'unsupported-os')));\"`/hermesc -emit-binary -O -out bundle/android/App.js bundle/android/App.text.js -output-source-map",
Expand Down
Loading
Loading