Skip to content

Commit 44b0284

Browse files
committed
chore: extend test script to support macOS and visionOS
1 parent ed50cdc commit 44b0284

File tree

1 file changed

+69
-36
lines changed

1 file changed

+69
-36
lines changed

scripts/testing/test-matrix.mts

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,34 @@ type PlatformConfig = {
1818
engines: ReadonlyArray<"hermes" | "jsc">;
1919
isAvailable: (config: Required<BuildConfig>) => boolean;
2020
prebuild: (config: Required<BuildConfig>) => Promise<void>;
21+
requiresManualTesting?: boolean;
2122
};
2223

2324
const DEFAULT_PLATFORMS = ["android", "ios"];
2425
const TEST_VARIANTS = ["paper", "fabric"] as const;
2526

27+
function isVariantSupported({ version, variant }: Required<BuildConfig>) {
28+
return variant === "fabric" || toVersionNumber(version) < v(0, 82, 0);
29+
}
30+
31+
function isAppleVariantSupported(config: Required<BuildConfig>) {
32+
if (process.platform !== "darwin") {
33+
return false;
34+
}
35+
36+
const { version, engine } = config;
37+
if (engine === "jsc" && toVersionNumber(version) >= v(0, 80, 0)) {
38+
return false;
39+
}
40+
41+
return isVariantSupported(config);
42+
}
43+
2644
const PLATFORM_CONFIG: Record<TargetPlatform, PlatformConfig> = {
2745
android: {
2846
name: "Android",
2947
engines: ["hermes"],
30-
isAvailable: ({ engine }) => engine === "hermes",
48+
isAvailable: isVariantSupported,
3149
prebuild: ({ variant }) => {
3250
if (variant === "fabric") {
3351
const properties = "android/gradle.properties";
@@ -43,36 +61,29 @@ const PLATFORM_CONFIG: Record<TargetPlatform, PlatformConfig> = {
4361
ios: {
4462
name: "iOS",
4563
engines: ["jsc", "hermes"],
46-
isAvailable: ({ version, engine }) => {
47-
if (process.platform !== "darwin") {
48-
return false;
49-
}
50-
51-
if (engine === "jsc" && toVersionNumber(version) >= v(0, 80, 0)) {
52-
return false;
53-
}
54-
55-
return true;
56-
},
64+
isAvailable: isAppleVariantSupported,
5765
prebuild: installPods,
5866
},
5967
macos: {
6068
name: "macOS",
6169
engines: ["jsc", "hermes"],
62-
isAvailable: () => false,
70+
isAvailable: isAppleVariantSupported,
6371
prebuild: installPods,
72+
requiresManualTesting: true,
6473
},
6574
visionos: {
6675
name: "visionOS",
6776
engines: ["jsc", "hermes"],
68-
isAvailable: () => false,
77+
isAvailable: isAppleVariantSupported,
6978
prebuild: installPods,
79+
requiresManualTesting: true,
7080
},
7181
windows: {
7282
name: "Windows",
7383
engines: ["hermes"],
7484
isAvailable: () => false,
7585
prebuild: () => Promise.resolve(),
86+
requiresManualTesting: true,
7687
},
7788
};
7889

@@ -124,11 +135,11 @@ function validatePlatforms(platforms: string[]): TargetPlatform[] {
124135
switch (platform) {
125136
case "android":
126137
case "ios":
138+
case "macos":
139+
case "visionos":
127140
filtered.push(platform);
128141
break;
129142

130-
case "macos":
131-
case "visionos":
132143
case "windows":
133144
log(yellow(`⚠ Unsupported platform: ${platform}`));
134145
break;
@@ -153,6 +164,14 @@ function parseArgs(args: string[]) {
153164
description: "Test iOS",
154165
type: "boolean",
155166
},
167+
macos: {
168+
description: "Test macOS",
169+
type: "boolean",
170+
},
171+
visionos: {
172+
description: "Test visionOS",
173+
type: "boolean",
174+
},
156175
},
157176
strict: true,
158177
allowPositionals: true,
@@ -168,10 +187,10 @@ function parseArgs(args: string[]) {
168187
};
169188
}
170189

171-
function prestart() {
190+
function waitForUserInput(message: string): Promise<void> {
172191
return !process.stdin.isTTY
173192
? Promise.resolve()
174-
: new Promise((resolve) => {
193+
: new Promise((resolve, reject) => {
175194
const stdin = process.stdin;
176195
const rawMode = stdin.isRaw;
177196
const encoding = stdin.readableEncoding || undefined;
@@ -185,19 +204,17 @@ function prestart() {
185204
stdin.setRawMode(rawMode);
186205
if (typeof key === "string" && key === "\u0003") {
187206
showBanner("❌ Canceled");
188-
// eslint-disable-next-line local/no-process-exit
189-
process.exit(1);
207+
reject(1);
208+
} else {
209+
resolve();
190210
}
191-
resolve(true);
192211
});
193-
process.stdout.write(
194-
`${TAG} Before continuing, make sure all emulators/simulators and Appium/Metro instances are closed.\n${TAG}\n${TAG} Press any key to continue...`
195-
);
212+
process.stdout.write(message);
196213
});
197214
}
198215

199216
/**
200-
* Invokes `react-native run-<platform>`.
217+
* Invokes `rnx-cli run --platform <platform>`.
201218
*/
202219
function buildAndRun(platform: TargetPlatform) {
203220
switch (platform) {
@@ -229,7 +246,15 @@ async function buildRunTest({ version, platform, variant }: BuildConfig) {
229246
showBanner(`Build ${setup.name} [${variant}, ${engine}]`);
230247
await setup.prebuild(configWithEngine);
231248
buildAndRun(platform);
232-
await test(platform, [variant, engine]);
249+
if (setup.requiresManualTesting) {
250+
await waitForUserInput(
251+
yellow(
252+
`⚠ ${setup.name} requires manual testing. When you're done, press any key to continue...`
253+
)
254+
);
255+
} else {
256+
await test(platform, [variant, engine]);
257+
}
233258
}
234259
}
235260

@@ -265,7 +290,7 @@ async function withReactNativeVersion(
265290
reset(rootDir);
266291

267292
if (version) {
268-
await setReactVersion(version, true);
293+
await setReactVersion(version, false);
269294
} else {
270295
log();
271296
}
@@ -291,15 +316,20 @@ if (platforms.length === 0) {
291316
process.exitCode = 1;
292317
showBanner(red("No valid platforms were specified"));
293318
} else {
294-
TEST_VARIANTS.reduce((job, variant) => {
295-
return job.then(() =>
296-
withReactNativeVersion(version, async () => {
297-
for (const platform of platforms) {
298-
await buildRunTest({ version, platform, variant });
299-
}
300-
})
301-
);
302-
}, prestart())
319+
TEST_VARIANTS.reduce(
320+
(job, variant) => {
321+
return job.then(() =>
322+
withReactNativeVersion(version, async () => {
323+
for (const platform of platforms) {
324+
await buildRunTest({ version, platform, variant });
325+
}
326+
})
327+
);
328+
},
329+
waitForUserInput(
330+
`${TAG} Before continuing, make sure all emulators/simulators and Appium/Metro instances are closed.\n${TAG}\n${TAG} Press any key to continue...`
331+
)
332+
)
303333
.then(() => {
304334
showBanner("Initialize new app");
305335
$(
@@ -337,5 +367,8 @@ if (platforms.length === 0) {
337367
})
338368
.then(() => {
339369
showBanner(green("✔ Pass"));
370+
})
371+
.catch((exitCode) => {
372+
process.exitCode = exitCode ?? 1;
340373
});
341374
}

0 commit comments

Comments
 (0)