Skip to content

Commit 565eaa4

Browse files
Ievgenii.MykhalevskyiIevgenii.Mykhalevskyi
Ievgenii.Mykhalevskyi
authored and
Ievgenii.Mykhalevskyi
committed
optimised SimulatorFocus usage for tests
1 parent c0b9525 commit 565eaa4

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/Debug/DebugAdapterTracker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export class DebugAdapterTracker implements vscode.DebugAdapterTracker {
3333
private get isCoverage(): boolean {
3434
return this.debugSession.configuration.isCoverage;
3535
}
36+
private get processExe(): string {
37+
return this.debugSession.configuration.processExe;
38+
}
3639
private get context() {
3740
return DebugConfigurationProvider.getContextForSession(this.sessionID)!;
3841
}
@@ -48,15 +51,15 @@ export class DebugAdapterTracker implements vscode.DebugAdapterTracker {
4851
this.debugSession = debugSession;
4952
this.problemResolver = problemResolver;
5053
this._stream = fs.createWriteStream(getFilePathInWorkspace(this.logPath), { flags: "a+" });
51-
this.simulatorInteractor = new SimulatorFocus(this.context.commandContext);
54+
this.simulatorInteractor = new SimulatorFocus();
5255
}
5356

5457
private get logPath(): string {
5558
return this.debugSession.configuration.logPath;
5659
}
5760

5861
onWillStartSession() {
59-
this.simulatorInteractor.init();
62+
this.simulatorInteractor.init(this.context.commandContext.projectEnv, this.processExe);
6063
console.log("Session is starting");
6164
vscode.debug.activeDebugSession;
6265
this.disList.push(

src/Debug/DebugConfigurationProvider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,16 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
167167
if (testToRun.length === 0) {
168168
continue;
169169
}
170+
const device = await context.projectEnv.debugDeviceID;
170171
const debugSession: vscode.DebugConfiguration = {
171172
type: "xcode-lldb",
172173
name: `Xcode: Testing: ${session.target}`,
173174
request: "launch",
174175
target: "tests",
175-
isDebuggable: isDebuggable,
176+
isDebuggable:
177+
device.platform === "macOS" && session.host.includes("-Runner.app")
178+
? false
179+
: isDebuggable, // for macOS, we can not debug UITests as it freezes for some reason
176180
sessionId: sessionId,
177181
testsToRun: testToRun,
178182
buildBeforeLaunch: "never",
@@ -386,6 +390,7 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
386390
deviceID: deviceID.id,
387391
xctestrun: dbgConfig.xctestrun,
388392
isCoverage: dbgConfig.isCoverage,
393+
processExe: processExe,
389394
};
390395
return debugSession;
391396
} else {
@@ -434,6 +439,7 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv
434439
deviceID: deviceID.id,
435440
xctestrun: dbgConfig.xctestrun,
436441
isCoverage: dbgConfig.isCoverage,
442+
processExe: processExe,
437443
};
438444
return debugSession;
439445
}

src/Debug/SimulatorFocus.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { execSync } from "child_process";
2-
import { CommandContext } from "../CommandManagement/CommandContext";
3-
import { DeviceID } from "../env";
2+
import { DeviceID, ProjectEnv } from "../env";
3+
import path from "path";
44

55
export class SimulatorFocus {
6-
private context: CommandContext;
76
private deviceID?: DeviceID;
87
private productName?: string;
98

10-
constructor(context: CommandContext) {
11-
this.context = context;
12-
}
9+
constructor() {}
1310

14-
async init() {
15-
this.deviceID = await this.context.projectEnv.debugDeviceID;
16-
this.productName = await this.context.projectEnv.productName;
11+
async init(projectEnv: ProjectEnv, processExe: string) {
12+
this.deviceID = await projectEnv.debugDeviceID;
13+
this.productName = processExe.split(path.sep).at(0);
14+
if (this.productName === undefined) {
15+
this.productName = await projectEnv.productName;
16+
} else if (this.productName.endsWith(".app")) {
17+
this.productName = this.productName.slice(0, -".app".length);
18+
}
1719
}
1820

1921
focus() {

0 commit comments

Comments
 (0)