Skip to content

Commit bfd76c7

Browse files
authored
ci(macOS): Restore CI pipeline (#502)
1 parent 02e56ba commit bfd76c7

File tree

5 files changed

+120
-56
lines changed

5 files changed

+120
-56
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
jobs:
8+
macos:
9+
name: "macOS"
10+
runs-on: macos-latest
11+
steps:
12+
- name: Set up Node.js
13+
uses: actions/setup-node@v1
14+
with:
15+
node-version: 14
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
- name: Cache /.cache/yarn
19+
uses: actions/cache@v2
20+
with:
21+
path: .cache/yarn
22+
key: ${{ hashFiles('yarn.lock') }}
23+
- name: Install JS dependencies
24+
run: |
25+
yarn --pure-lockfile --non-interactive --cache-folder .cache/yarn
26+
- name: Bundle JS
27+
run: |
28+
yarn bundle:macos
29+
- name: Install macOS dependencies
30+
run: |
31+
pod install
32+
working-directory: example/macos
33+
- name: Build and test
34+
run: |
35+
yarn test:e2e:macos

example/app.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
],
1313
"ios": [
1414
"index.ios.jsbundle"
15+
],
16+
"macos": [
17+
"index.macos.jsbundle"
1518
]
1619
}
1720
}

example/macos/AsyncStorageExample-macOSUITests/AsyncStorageExample_macOSUITests.m

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,28 @@ - (void)setUp
2828
_app = [[XCUIApplication alloc] init];
2929
[_app launch];
3030

31-
_window = _app.windows[@"RNCAsyncStorageExample macOS"];
32-
XCTAssert(_window.exists);
31+
NSPredicate *exists = [NSPredicate predicateWithFormat:@"exists == 1"];
32+
33+
_window = _app.windows[@"AsyncStorageExample"];
34+
[self waitForExpectation:exists evaluatedWithObject:_window timeout:5];
3335

3436
_restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch;
35-
XCTAssert(_restartButton.exists);
37+
[self waitForExpectation:exists evaluatedWithObject:_restartButton timeout:5];
3638

3739
_getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch;
38-
XCTAssert(_getSetClearButton.exists);
40+
[self waitForExpectation:exists evaluatedWithObject:_getSetClearButton timeout:5];
3941

4042
_mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch;
41-
XCTAssert(_mergeItemButton.exists);
43+
[self waitForExpectation:exists evaluatedWithObject:_mergeItemButton timeout:5];
4244

43-
[self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"];
45+
[self setDelegate];
46+
[self clear];
47+
[self unsetDelegate];
48+
[self clear];
4449
}
4550

4651
- (void)testShouldStoreValueInAsyncStorage
4752
{
48-
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
49-
5053
[_getSetClearButton click];
5154

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

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

67-
XCTAssertEqualObjects(storedNumber.label, expectedText);
70+
XCTAssertEqualObjects(storedNumber.value, expectedText);
6871
}
6972

7073
- (void)testShouldClearItem
7174
{
72-
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
73-
7475
[_getSetClearButton click];
7576

7677
XCUIElement *increaseBy10Button =
@@ -85,36 +86,8 @@ - (void)testShouldClearItem
8586
XCTAssertEqualObjects(storedNumber.label, @"");
8687
}
8788

88-
- (NSString *)performInputWithFormat:format
89-
{
90-
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
91-
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
92-
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
93-
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";
94-
95-
XCUIElement *nameInput = _window.textFields[@"testInput-name"];
96-
[nameInput click];
97-
[nameInput typeText:name];
98-
99-
XCUIElement *ageInput = _window.textFields[@"testInput-age"];
100-
[ageInput click];
101-
[ageInput typeText:age];
102-
103-
XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
104-
[eyesInput click];
105-
[eyesInput typeText:eyeColor];
106-
107-
XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
108-
[showInput click];
109-
[showInput typeText:shoeSize];
110-
111-
return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
112-
}
113-
11489
- (void)testShouldMergeItemsInAsyncStorage
11590
{
116-
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
117-
11891
[_mergeItemButton click];
11992

12093
XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
@@ -128,7 +101,7 @@ - (void)testShouldMergeItemsInAsyncStorage
128101
[saveItemButton click];
129102
[_restartButton click];
130103
[restoreItemButton click];
131-
XCTAssertEqualObjects(storyText.label, story);
104+
XCTAssertEqualObjects(storyText.value, story);
132105
[_restartButton click];
133106

134107
// merging here
@@ -137,16 +110,15 @@ - (void)testShouldMergeItemsInAsyncStorage
137110
[mergeItemButton click];
138111
[_restartButton click];
139112
[restoreItemButton click];
140-
XCTAssertEqualObjects(storyText.label, newStory);
113+
XCTAssertEqualObjects(storyText.value, newStory);
141114
}
142115

143116
- (void)testMergeItemDelegate
144117
{
145-
[self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"];
118+
[self setDelegate];
146119

147120
[_mergeItemButton click];
148121

149-
XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
150122
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
151123
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
152124
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];
@@ -157,13 +129,69 @@ - (void)testMergeItemDelegate
157129
[mergeItemButton click];
158130
[_restartButton click];
159131
[restoreItemButton click];
160-
XCTAssertEqualObjects(storyText.label, story);
132+
XCTAssertEqualObjects(storyText.value, story);
133+
}
134+
135+
#pragma mark - Private
136+
137+
- (void)clear
138+
{
139+
[_getSetClearButton click];
140+
[self clickButton:@"clear_button"];
141+
}
142+
143+
- (void)clickButton:(NSString *)identifier
144+
{
145+
NSPredicate *exists = [NSPredicate predicateWithFormat:@"exists == 1"];
146+
XCUIElement *button = _window.buttons[identifier].staticTexts.firstMatch;
147+
[self waitForExpectation:exists evaluatedWithObject:button timeout:5];
148+
[button click];
149+
}
150+
151+
- (NSString *)performInputWithFormat:format
152+
{
153+
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
154+
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
155+
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
156+
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";
157+
158+
XCUIElement *nameInput = _window.textFields[@"testInput-name"];
159+
[nameInput click];
160+
[nameInput typeText:name];
161+
162+
XCUIElement *ageInput = _window.textFields[@"testInput-age"];
163+
[ageInput click];
164+
[ageInput typeText:age];
165+
166+
XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
167+
[eyesInput click];
168+
[eyesInput typeText:eyeColor];
169+
170+
XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
171+
[showInput click];
172+
[showInput typeText:shoeSize];
173+
174+
return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
175+
}
176+
177+
- (void)setDelegate
178+
{
179+
[_mergeItemButton click];
180+
[self clickButton:@"setDelegate_button"];
181+
}
182+
183+
- (void)unsetDelegate
184+
{
185+
[_mergeItemButton click];
186+
[self clickButton:@"unsetDelegate_button"];
161187
}
162188

163-
- (void)sendTestAppCommand:(NSString *)URLString
189+
- (void)waitForExpectation:(NSPredicate *)predicate
190+
evaluatedWithObject:(id)object
191+
timeout:(NSTimeInterval)timeout
164192
{
165-
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]];
166-
sleep(.25);
193+
[self expectationForPredicate:predicate evaluatedWithObject:object handler:nil];
194+
[self waitForExpectationsWithTimeout:timeout handler:nil];
167195
}
168196

169197
@end

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"build:e2e:macos": "scripts/macos_e2e.sh 'build'",
5151
"bundle:android": "scripts/android_e2e.sh 'bundle'",
5252
"bundle:ios": "scripts/ios_e2e.sh 'bundle'",
53+
"bundle:macos": "react-native bundle --entry-file index.js --platform macos --bundle-output example/index.macos.jsbundle --use-react-native-macos",
5354
"test": "yarn test:lint && yarn test:flow",
5455
"test:flow": "flow check",
5556
"test:lint": "eslint src/**/*.js example/**/*.js jest/*.js",

scripts/macos_e2e.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
#!/bin/bash
22

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

9-
echo "[XCode e2e] Building macOS project"
10-
export RCT_NO_LAUNCH_PACKAGER=true
5+
# Workaround for `Element StaticText, {{163.0, 836.0}, {156.0, 21.0}}, value: Set native delegate is not hittable`.
6+
# This occurs when a button is not visible in the window. We resize the window
7+
# here to ensure that it is.
8+
defaults write com.microsoft.ReactTestApp "NSWindow Frame MainWindow" "0 0 800 500 0 0 2560 1417 "
9+
1110
xcodebuild \
12-
-project example/macos/AsyncStorageExample.xcworkspace \
11+
-workspace example/macos/AsyncStorageExample.xcworkspace \
1312
-scheme ReactTestApp \
1413
-configuration Release \
1514
-sdk macosx \
1615
-derivedDataPath example/macos/build \
17-
BUNDLE_FILE="$BUNDLE_FILE" \
18-
EXTRA_PACKAGER_ARGS="$EXTRA_PACKAGER_ARGS" \
1916
$BUILD_ACTIONS
2017

2118
exit $?

0 commit comments

Comments
 (0)