Skip to content

ci(macOS): Restore CI pipeline #502

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

Merged
merged 1 commit into from
Dec 4, 2020
Merged
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
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI
on:
push:
branches:
- master
pull_request:
jobs:
macos:
name: "macOS"
runs-on: macos-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Checkout
uses: actions/checkout@v2
- name: Cache /.cache/yarn
uses: actions/cache@v2
with:
path: .cache/yarn
key: ${{ hashFiles('yarn.lock') }}
- name: Install JS dependencies
run: |
yarn --pure-lockfile --non-interactive --cache-folder .cache/yarn
- name: Bundle JS
run: |
yarn bundle:macos
- name: Install macOS dependencies
run: |
pod install
working-directory: example/macos
- name: Build and test
run: |
yarn test:e2e:macos
3 changes: 3 additions & 0 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
],
"ios": [
"index.ios.jsbundle"
],
"macos": [
"index.macos.jsbundle"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,28 @@ - (void)setUp
_app = [[XCUIApplication alloc] init];
[_app launch];

_window = _app.windows[@"RNCAsyncStorageExample macOS"];
XCTAssert(_window.exists);
NSPredicate *exists = [NSPredicate predicateWithFormat:@"exists == 1"];

_window = _app.windows[@"AsyncStorageExample"];
[self waitForExpectation:exists evaluatedWithObject:_window timeout:5];

_restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch;
XCTAssert(_restartButton.exists);
[self waitForExpectation:exists evaluatedWithObject:_restartButton timeout:5];

_getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch;
XCTAssert(_getSetClearButton.exists);
[self waitForExpectation:exists evaluatedWithObject:_getSetClearButton timeout:5];

_mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch;
XCTAssert(_mergeItemButton.exists);
[self waitForExpectation:exists evaluatedWithObject:_mergeItemButton timeout:5];

[self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"];
[self setDelegate];
[self clear];
[self unsetDelegate];
[self clear];
}

- (void)testShouldStoreValueInAsyncStorage
{
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];

[_getSetClearButton click];

XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
Expand All @@ -64,13 +67,11 @@ - (void)testShouldStoreValueInAsyncStorage

NSString *expectedText = [NSString stringWithFormat:@"%d", tapTimes * 10];

XCTAssertEqualObjects(storedNumber.label, expectedText);
XCTAssertEqualObjects(storedNumber.value, expectedText);
}

- (void)testShouldClearItem
{
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];

[_getSetClearButton click];

XCUIElement *increaseBy10Button =
Expand All @@ -85,36 +86,8 @@ - (void)testShouldClearItem
XCTAssertEqualObjects(storedNumber.label, @"");
}

- (NSString *)performInputWithFormat:format
{
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";

XCUIElement *nameInput = _window.textFields[@"testInput-name"];
[nameInput click];
[nameInput typeText:name];

XCUIElement *ageInput = _window.textFields[@"testInput-age"];
[ageInput click];
[ageInput typeText:age];

XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
[eyesInput click];
[eyesInput typeText:eyeColor];

XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
[showInput click];
[showInput typeText:shoeSize];

return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
}

- (void)testShouldMergeItemsInAsyncStorage
{
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];

[_mergeItemButton click];

XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
Expand All @@ -128,7 +101,7 @@ - (void)testShouldMergeItemsInAsyncStorage
[saveItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, story);
XCTAssertEqualObjects(storyText.value, story);
[_restartButton click];

// merging here
Expand All @@ -137,16 +110,15 @@ - (void)testShouldMergeItemsInAsyncStorage
[mergeItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, newStory);
XCTAssertEqualObjects(storyText.value, newStory);
}

- (void)testMergeItemDelegate
{
[self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"];
[self setDelegate];

[_mergeItemButton click];

XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];
Expand All @@ -157,13 +129,69 @@ - (void)testMergeItemDelegate
[mergeItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, story);
XCTAssertEqualObjects(storyText.value, story);
}

#pragma mark - Private

- (void)clear
{
[_getSetClearButton click];
[self clickButton:@"clear_button"];
}

- (void)clickButton:(NSString *)identifier
{
NSPredicate *exists = [NSPredicate predicateWithFormat:@"exists == 1"];
XCUIElement *button = _window.buttons[identifier].staticTexts.firstMatch;
[self waitForExpectation:exists evaluatedWithObject:button timeout:5];
[button click];
}

- (NSString *)performInputWithFormat:format
{
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";

XCUIElement *nameInput = _window.textFields[@"testInput-name"];
[nameInput click];
[nameInput typeText:name];

XCUIElement *ageInput = _window.textFields[@"testInput-age"];
[ageInput click];
[ageInput typeText:age];

XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
[eyesInput click];
[eyesInput typeText:eyeColor];

XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
[showInput click];
[showInput typeText:shoeSize];

return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
}

- (void)setDelegate
{
[_mergeItemButton click];
[self clickButton:@"setDelegate_button"];
}

- (void)unsetDelegate
{
[_mergeItemButton click];
[self clickButton:@"unsetDelegate_button"];
}

- (void)sendTestAppCommand:(NSString *)URLString
- (void)waitForExpectation:(NSPredicate *)predicate
evaluatedWithObject:(id)object
timeout:(NSTimeInterval)timeout
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]];
sleep(.25);
[self expectationForPredicate:predicate evaluatedWithObject:object handler:nil];
[self waitForExpectationsWithTimeout:timeout handler:nil];
}

@end
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"build:e2e:macos": "scripts/macos_e2e.sh 'build'",
"bundle:android": "scripts/android_e2e.sh 'bundle'",
"bundle:ios": "scripts/ios_e2e.sh 'bundle'",
"bundle:macos": "react-native bundle --entry-file index.js --platform macos --bundle-output example/index.macos.jsbundle --use-react-native-macos",
"test": "yarn test:lint && yarn test:flow",
"test:flow": "flow check",
"test:lint": "eslint src/**/*.js example/**/*.js jest/*.js",
Expand Down
15 changes: 6 additions & 9 deletions scripts/macos_e2e.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#!/bin/bash

RESOURCE_DIR="$PWD/example/ios/build/Build/Products/Release-macosx/ReactTestApp.app"
ENTRY_FILE="example/index.js"
BUNDLE_FILE="$RESOURCE_DIR/main.jsbundle"
EXTRA_PACKAGER_ARGS="--entry-file=$ENTRY_FILE --use-react-native-macos"
BUILD_ACTIONS="$@"

echo "[XCode e2e] Building macOS project"
export RCT_NO_LAUNCH_PACKAGER=true
# Workaround for `Element StaticText, {{163.0, 836.0}, {156.0, 21.0}}, value: Set native delegate is not hittable`.
# This occurs when a button is not visible in the window. We resize the window
# here to ensure that it is.
defaults write com.microsoft.ReactTestApp "NSWindow Frame MainWindow" "0 0 800 500 0 0 2560 1417 "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice hack 🤞


xcodebuild \
-project example/macos/AsyncStorageExample.xcworkspace \
-workspace example/macos/AsyncStorageExample.xcworkspace \
-scheme ReactTestApp \
-configuration Release \
-sdk macosx \
-derivedDataPath example/macos/build \
BUNDLE_FILE="$BUNDLE_FILE" \
EXTRA_PACKAGER_ARGS="$EXTRA_PACKAGER_ARGS" \
$BUILD_ACTIONS

exit $?