Skip to content

Commit 3caaf09

Browse files
Fix debug command and unit tests
1 parent 5495194 commit 3caaf09

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

lib/commands/debug.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ import { DebugCommandErrors } from "../constants";
44

55
export class DebugPlatformCommand implements ICommand {
66
public allowedParameters: ICommandParameter[] = [];
7-
public platform: string;
87

9-
constructor(protected $devicesService: Mobile.IDevicesService,
8+
constructor(private debugService: IPlatformDebugService,
9+
private platform: string,
10+
protected $devicesService: Mobile.IDevicesService,
1011
protected $platformService: IPlatformService,
1112
protected $projectData: IProjectData,
1213
protected $options: IOptions,
1314
protected $platformsData: IPlatformsData,
1415
protected $logger: ILogger,
1516
protected $errors: IErrors,
16-
private debugService: IPlatformDebugService,
1717
private $debugDataService: IDebugDataService,
1818
private $debugLiveSyncService: IDebugLiveSyncService,
1919
private $config: IConfiguration,
2020
private $prompter: IPrompter,
2121
private $liveSyncCommandHelper: ILiveSyncCommandHelper) {
22-
this.$projectData.initializeProjectData();
2322
}
2423

2524
public async execute(args: string[]): Promise<void> {
@@ -119,7 +118,7 @@ export class DebugPlatformCommand implements ICommand {
119118

120119
export class DebugIOSCommand implements ICommand {
121120
private get debugPlatformCommand(): DebugPlatformCommand {
122-
return this.$injector.resolve<DebugPlatformCommand>(DebugPlatformCommand);
121+
return this.$injector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: this.$iOSDebugService, platform: this.platform });
123122
}
124123

125124
public allowedParameters: ICommandParameter[] = [];
@@ -131,8 +130,9 @@ export class DebugIOSCommand implements ICommand {
131130
private $injector: IInjector,
132131
private $projectData: IProjectData,
133132
private $platformsData: IPlatformsData,
133+
private $iOSDebugService: IDebugService,
134134
$iosDeviceOperations: IIOSDeviceOperations) {
135-
135+
this.$projectData.initializeProjectData();
136136
// Do not dispose ios-device-lib, so the process will remain alive and the debug application (NativeScript Inspector or Chrome DevTools) will be able to connect to the socket.
137137
// In case we dispose ios-device-lib, the socket will be closed and the code will fail when the debug application tries to read/send data to device socket.
138138
// That's why the `$ tns debug ios --justlaunch` command will not release the terminal.
@@ -159,7 +159,7 @@ $injector.registerCommand("debug|ios", DebugIOSCommand);
159159

160160
export class DebugAndroidCommand implements ICommand {
161161
private get debugPlatformCommand(): DebugPlatformCommand {
162-
return this.$injector.resolve<DebugPlatformCommand>(DebugPlatformCommand);
162+
return this.$injector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: this.$androidDebugService, platform: this.platform });
163163
}
164164

165165
public allowedParameters: ICommandParameter[] = [];
@@ -170,7 +170,10 @@ export class DebugAndroidCommand implements ICommand {
170170
private $options: IOptions,
171171
private $injector: IInjector,
172172
private $projectData: IProjectData,
173-
private $platformsData: IPlatformsData) { }
173+
private $platformsData: IPlatformsData,
174+
private $androidDebugService: IDebugService) {
175+
this.$projectData.initializeProjectData();
176+
}
174177

175178
public execute(args: string[]): Promise<void> {
176179
return this.debugPlatformCommand.execute(args);

lib/common

test/debug.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ function createTestInjector(): IInjector {
6868

6969
testInjector.register("prompter", {});
7070
testInjector.registerCommand("debug|android", DebugAndroidCommand);
71+
testInjector.register("liveSyncCommandHelper", {
72+
getDevicesLiveSyncInfo: async (): Promise<IDevicesDescriptorsLiveSyncInfo> => {
73+
return { deviceDescriptors: [], liveSyncInfo: null };
74+
}
75+
});
7176

7277
return testInjector;
7378
}
@@ -78,7 +83,7 @@ describe("debug command tests", () => {
7883
const testInjector = createTestInjector();
7984
const options = testInjector.resolve<IOptions>("options");
8085
options.forDevice = options.emulator = true;
81-
const debugCommand = <DebugPlatformCommand>testInjector.resolve(DebugPlatformCommand);
86+
const debugCommand = testInjector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: {}, platform: "android" });
8287
await assert.isRejected(debugCommand.getDeviceForDebug(), DebugCommandErrors.UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR);
8388
});
8489

@@ -95,7 +100,7 @@ describe("debug command tests", () => {
95100

96101
const options = testInjector.resolve<IOptions>("options");
97102
options.device = specifiedDeviceOption;
98-
const debugCommand = <DebugPlatformCommand>testInjector.resolve(DebugPlatformCommand);
103+
const debugCommand = testInjector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: {}, platform: "android" });
99104
const selectedDeviceInstance = await debugCommand.getDeviceForDebug();
100105
assert.deepEqual(selectedDeviceInstance, deviceInstance);
101106
});
@@ -111,7 +116,7 @@ describe("debug command tests", () => {
111116
const devicesService = testInjector.resolve<Mobile.IDevicesService>("devicesService");
112117
devicesService.getDeviceInstances = (): Mobile.IDevice[] => getDeviceInstancesResult;
113118

114-
const debugCommand = <DebugPlatformCommand>testInjector.resolve(DebugPlatformCommand);
119+
const debugCommand = testInjector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: {}, platform: "android" });
115120
await assert.isRejected(debugCommand.getDeviceForDebug(), DebugCommandErrors.NO_DEVICES_EMULATORS_FOUND_FOR_OPTIONS);
116121
};
117122

@@ -184,7 +189,7 @@ describe("debug command tests", () => {
184189
const devicesService = testInjector.resolve<Mobile.IDevicesService>("devicesService");
185190
devicesService.getDeviceInstances = (): Mobile.IDevice[] => [deviceInstance];
186191

187-
const debugCommand = <DebugPlatformCommand>testInjector.resolve(DebugPlatformCommand);
192+
const debugCommand = testInjector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: {}, platform: "android" });
188193
const actualDeviceInstance = await debugCommand.getDeviceForDebug();
189194
assert.deepEqual(actualDeviceInstance, deviceInstance);
190195
});
@@ -243,7 +248,7 @@ describe("debug command tests", () => {
243248
return choices[1];
244249
};
245250

246-
const debugCommand = <DebugPlatformCommand>testInjector.resolve(DebugPlatformCommand);
251+
const debugCommand = testInjector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: {}, platform: "android" });
247252
const actualDeviceInstance = await debugCommand.getDeviceForDebug();
248253
const expectedChoicesPassedToPrompter = [deviceInstance1, deviceInstance2].map(d => `${d.deviceInfo.identifier} - ${d.deviceInfo.displayName}`);
249254
assert.deepEqual(choicesPassedToPrompter, expectedChoicesPassedToPrompter);
@@ -304,7 +309,7 @@ describe("debug command tests", () => {
304309

305310
devicesService.getDeviceInstances = (): Mobile.IDevice[] => deviceInstances;
306311

307-
const debugCommand = <DebugPlatformCommand>testInjector.resolve(DebugPlatformCommand);
312+
const debugCommand = testInjector.resolve<DebugPlatformCommand>(DebugPlatformCommand, { debugService: {}, platform: "android" });
308313
const actualDeviceInstance = await debugCommand.getDeviceForDebug();
309314

310315
assert.deepEqual(actualDeviceInstance, deviceInstance2);

0 commit comments

Comments
 (0)