Skip to content
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
19 changes: 12 additions & 7 deletions packages/vscode-extension/shims/maestro/xcrun
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ REAL_XCRUN=$(PATH="${PATH//$SCRIPT_DIR:/}" command -v xcrun)

# If --set is specified respect that and pass through unchanged
for arg in "$@"; do
if [[ "$arg" == "--set" ]]; then
exec "$REAL_XCRUN" "$@"
fi
if [[ "$arg" == "--set" ]]; then
exec "$REAL_XCRUN" "$@"
fi
done

# If the subcommand is 'simctl', inject --set <CUSTOM_DEVICE_SET> after 'simctl'
# If the subcommand is 'simctl', inject --set $__RADON_CUSTOM_DEVICE_SET after 'simctl'
if [[ "$1" == "simctl" ]]; then
exec "$REAL_XCRUN" "$1" --set "$CUSTOM_DEVICE_SET" "${@:2}"
# When launching the app, we may need to pass the metro port as well
if [[ $2 == "launch" && "$*" == *"$__RADON_APP_ID"* ]]; then
exec "$REAL_XCRUN" "$1" --set "$__RADON_CUSTOM_DEVICE_SET" "${@:2}" $__RADON_LAUNCH_ARGS
else
exec "$REAL_XCRUN" "$1" --set "$__RADON_CUSTOM_DEVICE_SET" "${@:2}"
fi
else
exec "$REAL_XCRUN" "$@"
fi
exec "$REAL_XCRUN" "$@"
fi
5 changes: 3 additions & 2 deletions packages/vscode-extension/src/devices/AndroidDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ export abstract class AndroidDevice extends DeviceBase implements Disposable {
]);
}

public async forwardDevicePort(port: number) {
await exec(ADB_PATH, ["-s", this.serial, "reverse", `tcp:${port}`, `tcp:${port}`]);
public async forwardDevicePort(hostPort: number, devicePort?: number) {
devicePort ??= hostPort;
await exec(ADB_PATH, ["-s", this.serial, "reverse", `tcp:${devicePort}`, `tcp:${hostPort}`]);
}

public setUpKeyboard() {
Expand Down
30 changes: 25 additions & 5 deletions packages/vscode-extension/src/project/MaestroTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getOrCreateDeviceSet, IosSimulatorDevice } from "../devices/IosSimulato
import { extensionContext } from "../utilities/extensionContext";
import { Logger } from "../Logger";
import { getTelemetryReporter } from "../utilities/telemetry";
import { EXPO_GO_BUNDLE_ID, fetchExpoLaunchDeeplink } from "../builders/expoGo";

class MaestroPseudoTerminal implements vscode.Pseudoterminal {
private writeEmitter = new vscode.EventEmitter<string>();
Expand Down Expand Up @@ -69,15 +70,16 @@ function getDeviceFamily(deviceInfo: DeviceInfo) {
}

export class MaestroTestRunner implements Disposable {
private readonly device: DeviceBase;
private terminal: vscode.Terminal | undefined;
private pty: MaestroPseudoTerminal | undefined;
private maestroProcess: ChildProcess | undefined;
private onCloseTerminal: vscode.Disposable | undefined;

constructor(device: DeviceBase) {
this.device = device;
}
constructor(
private readonly device: DeviceBase,
private readonly metroPort: number,
private readonly applicationId: string
) {}

private getOrCreateTerminal(): { terminal: vscode.Terminal; pty: MaestroPseudoTerminal } {
if (this.terminal && this.pty) {
Expand Down Expand Up @@ -214,6 +216,7 @@ export class MaestroTestRunner implements Disposable {
// similar to what Maestro would do in prebuilt mode, and wrap the xcrun
// command to provide our own device set with the --set flag.
const shimPath = path.resolve(extensionContext.extensionPath, "shims", "maestro");
const launchArgs = await this.setupLaunchArguments();

const maestroProcess = exec("maestro", ["--device", this.device.id, "test", ...fileNames], {
buffer: false,
Expand All @@ -222,7 +225,9 @@ export class MaestroTestRunner implements Disposable {
cwd: homedir(),
env: {
PATH: `${shimPath}:${process.env.PATH}`,
CUSTOM_DEVICE_SET: getOrCreateDeviceSet(
__RADON_APP_ID: this.applicationId,
__RADON_LAUNCH_ARGS: launchArgs,
__RADON_CUSTOM_DEVICE_SET: getOrCreateDeviceSet(
this.device instanceof IosSimulatorDevice ? this.device.deviceInfo.id : undefined
),
},
Expand All @@ -246,6 +251,21 @@ export class MaestroTestRunner implements Disposable {
await maestroProcess;
}

private async setupLaunchArguments() {
if (this.device.platform !== DevicePlatform.IOS) {
return undefined;
}

const deepLinkChoice = this.applicationId === EXPO_GO_BUNDLE_ID ? "expo-go" : "expo-dev-client";
const expoDeepLink = await fetchExpoLaunchDeeplink(this.metroPort, "ios", deepLinkChoice);

if (expoDeepLink) {
return [`--initialUrl`, expoDeepLink].join(" ");
}

return [`-RCT_jsLocation`, `localhost:${this.metroPort}`].join(" ");
}

private async setupSimulatorSymlink() {
if (this.device.platform !== DevicePlatform.IOS) {
return async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/vscode-extension/src/project/applicationSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ export class ApplicationSession implements Disposable {
this.disposables.push(this.toolsManager);
this.disposables.push(this.stateManager);

this.maestroTestRunner = new MaestroTestRunner(this.device);
this.maestroTestRunner = new MaestroTestRunner(
this.device,
this.metro.port,
this.packageNameOrBundleId
);
this.disposables.push(this.maestroTestRunner);
}

Expand Down
Loading