Skip to content

Commit d684861

Browse files
committed
refactor(ios): drop the fixtures file's unreachable platform guards
The file-level guard already requires TARGET_OS_IOS, so the inner TARGET_OS_IOS pairs moved with the code can never be false. Also widen the package-side host-app scan to the whole target, matching the packager-side guard, and name the sibling owner of the fixture-argument pattern.
1 parent b30a101 commit d684861

4 files changed

Lines changed: 27 additions & 20 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#import <UIKit/UIKit.h>
1313
#import <UserNotifications/UserNotifications.h>
1414

15-
#if TARGET_OS_IOS
1615
// A plain text field whose accessibility value is the masked rendering of its text. This is how
1716
// a React Native `secureTextEntry` input reaches XCTest: `.textField`, not `.secureTextField`,
1817
// with a value of bullets (tester-army/e2e#872).
@@ -32,12 +31,10 @@ - (NSString *)accessibilityValue {
3231
}
3332

3433
@end
35-
#endif
3634

3735
@interface AgentDeviceRunnerFixtureViewController : AgentDeviceRunnerViewController
3836
@end
3937

40-
#if TARGET_OS_IOS
4138
@interface AgentDeviceRunnerFixtureViewController () <UNUserNotificationCenterDelegate>
4239
// Held for the app's lifetime: a window nobody retained would be gone before the test queried it.
4340
@property(nonatomic, strong) UIWindow *secondWindow;
@@ -233,12 +230,9 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField {
233230
return YES;
234231
}
235232
@end
236-
#endif
237233

238234
@implementation AgentDeviceRunnerFixtureViewController
239235

240-
241-
#if TARGET_OS_IOS
242236
// An animation that never ends is what "busy" looks like to XCTest while it decides whether the app
243237
// may receive an event: the app keeps reporting work in flight, which is the state that cost an alert
244238
// command its whole deadline in #2546. It stops the moment an alert button is answered, since that
@@ -568,9 +562,7 @@ - (void)moveTextEntryFieldUp {
568562
AgentDeviceTextEntryFieldTopInset - AgentDeviceTextEntryFieldHeight - AgentDeviceTextEntryNeighbourGap;
569563
[self.view layoutIfNeeded];
570564
}
571-
#endif
572565

573-
#if TARGET_OS_IOS
574566
- (void)agentDeviceMaskedToggleDidPress:(UIButton *)sender {
575567
(void)sender;
576568
self.maskedTogglePresses += 1;
@@ -592,7 +584,6 @@ - (void)updateMaskedToggleStatus {
592584
self.maskedToggleStatus.text =
593585
[NSString stringWithFormat:@"presses=%lu", (unsigned long)self.maskedTogglePresses];
594586
}
595-
#endif
596587

597588
- (void)navigationBackPressed {
598589
self.navigationBackStatus.text = @"Back performed";
@@ -620,7 +611,6 @@ - (void)viewDidLoad {
620611
UILabel *label = self.label;
621612

622613
// Keep the fixture behind a launch argument so normal runner snapshots remain unchanged.
623-
#if TARGET_OS_IOS
624614
if ([NSProcessInfo.processInfo.arguments containsObject:@"--agent-device-back-regression"]) {
625615
self.navigationBackStatus = label;
626616
label.accessibilityIdentifier = @"agent-device-back-status";
@@ -999,7 +989,6 @@ - (void)viewDidLoad {
999989
[visibleButton.topAnchor constraintEqualToAnchor:label.bottomAnchor constant:24],
1000990
]];
1001991
}
1002-
#endif
1003992
}
1004993

1005994
@end

‎scripts/__tests__/shipped-test-code.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ test('testOnlyContentFailures rejects a --agent-device-* fixture argument in the
8383
assert.match(failures[0], /--agent-device-\* fixture/);
8484
});
8585

86+
test('testOnlyContentFailures scans the packaged host app target at any depth', () => {
87+
// The packager-side guard scans the host app target recursively; this must not be shallower, or
88+
// a fixture screen under a subdirectory of the target ships while the re-check says nothing.
89+
const failures = testOnlyContentFailures([
90+
{
91+
path: 'dist/apple/runner/AgentDeviceRunner/AgentDeviceRunner/Screens/AgentDeviceFixtures.m',
92+
contents: '[arguments containsObject:@"--agent-device-crowded-screen"]',
93+
},
94+
]);
95+
assert.equal(failures.length, 1);
96+
});
97+
8698
test('testOnlyContentFailures accepts the packaged host app and product daemon code that name test tokens', () => {
8799
assert.deepEqual(
88100
testOnlyContentFailures([

‎scripts/lib/shipped-test-code.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,21 @@ export const DOCUMENTED_PACK_STUBS: ReadonlySet<string> = new Set([
3030
]);
3131

3232
/** Packaged-source locations scanned for test code that survived stripping, by path segments. */
33-
const RUNNER_SOURCE_APP_TARGET = ['AgentDeviceRunner', 'AgentDeviceRunner'];
3433
const RUNNER_SOURCE_ROOT = ['dist', 'apple', 'runner'];
34+
const RUNNER_HOST_APP_TARGET = [
35+
'dist',
36+
'apple',
37+
'runner',
38+
'AgentDeviceRunner',
39+
'AgentDeviceRunner',
40+
];
3541

3642
const UNIT_TEST_CONDITION = 'AGENT_DEVICE_RUNNER_UNIT_TESTS';
37-
/** The host app's fixture screens switch on these launch arguments; the shipped host must not carry one. */
43+
/**
44+
* The host app's fixture screens switch on these launch arguments; the shipped host must not carry
45+
* one. Owned here for the published package; scripts/package-apple-runner-source.mjs keeps the
46+
* matching copy for the pre-pack check, and the two are kept identical on purpose.
47+
*/
3848
const FIXTURE_LAUNCH_ARGUMENT = /"--agent-device-[^"]*"/;
3949

4050
/** One packed file: the `package.json`-relative path and the bytes the tarball carries. */
@@ -86,13 +96,7 @@ function isUnderRunnerSource(packedPath: string): boolean {
8696

8797
function isRunnerHostAppSource(packedPath: string): boolean {
8898
const parts = segments(packedPath);
89-
return (
90-
isUnderRunnerSource(packedPath) &&
91-
RUNNER_SOURCE_APP_TARGET.every(
92-
(segment, index) => parts[RUNNER_SOURCE_ROOT.length + index] === segment,
93-
) &&
94-
parts.length === RUNNER_SOURCE_ROOT.length + RUNNER_SOURCE_APP_TARGET.length + 1
95-
);
99+
return RUNNER_HOST_APP_TARGET.every((segment, index) => parts[index] === segment);
96100
}
97101

98102
/**

‎scripts/package-apple-runner-source.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const TEST_METHOD_PATTERN = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*(?:\w+\s+)*func\s+(te
5252
// on a fixture launch argument. AgentDeviceRunnerAppFixtures.m is dropped by skipFilePaths above;
5353
// this refuses the drop being widened or the fixtures returning under another name, and it is
5454
// what scripts/__tests__/packaged-runner-host-app.test.ts proves fires.
55+
// Kept identical to FIXTURE_LAUNCH_ARGUMENT in scripts/lib/shipped-test-code.ts, which applies the
56+
// same rule to the published package; this .mjs cannot import the .ts without a build step.
5557
const PACKAGED_HOST_APP_FIXTURE_ARGUMENT = /"--agent-device-[^"]*"/;
5658
const HOST_APP_TARGET_DIR = path.join('AgentDeviceRunner', 'AgentDeviceRunner');
5759

0 commit comments

Comments
 (0)