Skip to content

Commit 2737cac

Browse files
committed
test debugging
1 parent 2e8728f commit 2737cac

File tree

10 files changed

+97
-235
lines changed

10 files changed

+97
-235
lines changed

.settings/tasks.json

Lines changed: 0 additions & 201 deletions
This file was deleted.

docs/man_pages/project/testing/test-android.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ test android
33

44
Usage | Synopsis
55
------|-------
6-
General | `$ tns test android [--watch] [--device <Device ID>]`
6+
General | `$ tns test android [--watch] [--device <Device ID>] [--debug-brk]`
77

88
Runs the tests in your project on connected Android devices and emulators.
99

1010
### Options
1111
* `--watch` - If set, when you save changes to the project, changes are automatically synchronized to the connected device and tests are re-run.
1212
* `--device` - Specifies the serial number or the index of the connected device on which to run the tests. To list all connected devices, grouped by platform, run `$ tns device`
13+
* `--debug-brk` - Run the tests under the debugger. The debugger will break just before your tests are executed, so you have a chance to place breakpoints.
1314

1415
### Attributes
1516
* `<Device ID>` is the device index or identifier as listed by `$ tns device`

docs/man_pages/project/testing/test-ios.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ test ios
33

44
Usage | Synopsis
55
------|-------
6-
Run tests on all connected devices | `$ tns test ios [--watch]`
7-
Run tests on a selected device | `$ tns test ios --device <Device ID> [--watch]`
8-
Run tests in the iOS Simulator | `$ tns test ios --emulator [--watch]`
6+
Run tests on all connected devices | `$ tns test ios [--watch] [--debug-brk]`
7+
Run tests on a selected device | `$ tns test ios --device <Device ID> [--watch] [--debug-brk]`
8+
Run tests in the iOS Simulator | `$ tns test ios --emulator [--watch] [--debug-brk]`
99

1010
Runs the tests in your project on connected iOS devices or the iOS Simulator.
1111

1212
### Options
1313
* `--watch` - If set, when you save changes to the project, changes are automatically synchronized to the connected device and tests are re-ran.
1414
* `--device` - Specifies the serial number or the index of the connected device on which you want to run tests. To list all connected devices, grouped by platform, run `$ tns device`. You cannot set `--device` and `--emulator` simultaneously.
1515
* `--emulator` - Runs tests on the iOS Simulator. You cannot set `--device` and `--emulator` simultaneously.
16+
* `--debug-brk` - Run the tests under the debugger. The debugger will break just before your tests are executed, so you have a chance to place breakpoints.
1617

17-
<% if(isHtml) { %>
18+
<% if(isHtml) { %>
1819
### Related commands
1920
Command | Description
2021
--------|------------

lib/commands/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function RunTestCommandFactory(platform: string) {
1010
}
1111

1212
$injector.registerCommand("dev-test|android", RunTestCommandFactory('android'));
13-
$injector.registerCommand("dev-test|ios", RunTestCommandFactory('ios'));
13+
$injector.registerCommand("dev-test|ios", RunTestCommandFactory('iOS'));
1414

1515
function RunKarmaTestCommandFactory(platform: string) {
1616
return function RunKarmaTestCommand($testExecutionService: ITestExecutionService) {
@@ -20,4 +20,4 @@ function RunKarmaTestCommandFactory(platform: string) {
2020
}
2121

2222
$injector.registerCommand("test|android", RunKarmaTestCommandFactory('android'));
23-
$injector.registerCommand("test|ios", RunKarmaTestCommandFactory('ios'));
23+
$injector.registerCommand("test|ios", RunKarmaTestCommandFactory('iOS'));

lib/definitions/debug.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
interface IDebugService {
22
debug(): IFuture<void>;
3+
debugStart(): IFuture<void>;
34
}

lib/services/android-debug-service.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,34 @@ class AndroidDebugService implements IDebugService {
135135
this.device.applicationManager.uninstallApplication(packageName).wait();
136136
this.device.applicationManager.installApplication(packageFile).wait();
137137
}
138+
this.debugStartCore().wait();
139+
}).future<void>()();
140+
}
138141

142+
public debugStart(): IFuture<void> {
143+
return (() => {
144+
this.$devicesServices.initialize({ platform: this.platform, deviceId: this.$options.device}).wait();
145+
let action = (device: Mobile.IAndroidDevice): IFuture<void> => {
146+
this.device = device;
147+
return this.debugStartCore();
148+
};
149+
this.$devicesServices.execute(action).wait();
150+
}).future<void>()();
151+
}
152+
153+
private debugStartCore(): IFuture<void> {
154+
return (() => {
155+
let packageName = this.$projectData.projectId;
139156
let packageDir = util.format(AndroidDebugService.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName);
140157
let envDebugOutFullpath = this.$mobileHelper.buildDevicePath(packageDir, AndroidDebugService.ENV_DEBUG_OUT_FILENAME);
141158

142159
this.device.adb.executeShellCommand(["rm", `${envDebugOutFullpath}`]).wait();
143160
this.device.adb.executeShellCommand(["mkdir", "-p", `${packageDir}`]).wait();
144161

145-
let debugBreakPath = this.$mobileHelper.buildDevicePath(packageDir, "debugbreak");
162+
let debugBreakPath = this.$mobileHelper.buildDevicePath(packageDir, "debugbreak");
146163
this.device.adb.executeShellCommand([`cat /dev/null > ${debugBreakPath}`]).wait();
147164

165+
this.device.applicationManager.stopApplication(packageName).wait();
148166
this.device.applicationManager.startApplication(packageName).wait();
149167

150168
let dbgPort = this.startAndGetPort(packageName).wait();

lib/services/ios-debug-service.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,31 +152,42 @@ class IOSDebugService implements IDebugService {
152152
private deviceDebugBrk(): IFuture<void> {
153153
return (() => {
154154
this.$devicesServices.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
155-
this.$devicesServices.execute(device => (() => {
155+
this.$devicesServices.execute((device: iOSDevice.IOSDevice) => (() => {
156156
// we intentionally do not wait on this here, because if we did, we'd miss the AppLaunching notification
157157
let deploy = this.$platformService.deployOnDevice(this.platform);
158+
this.debugBrkCore(device).wait();
159+
deploy.wait();
160+
}).future<void>()()).wait();
161+
}).future<void>()();
162+
}
158163

159-
let iosDevice = <iOSDevice.IOSDevice>device;
160-
let projectId = this.$projectData.projectId;
161-
let npc = new iOSProxyServices.NotificationProxyClient(iosDevice, this.$injector);
164+
public debugStart(): IFuture<void> {
165+
return (() => {
166+
this.$devicesServices.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
167+
this.$devicesServices.execute((device: iOSDevice.IOSDevice) => this.debugBrkCore(device)).wait();
168+
}).future<void>()();
169+
}
162170

163-
try {
164-
let timeout = this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
165-
awaitNotification(npc, notification.appLaunching(projectId), timeout).wait();
166-
process.nextTick(() => {
167-
npc.postNotificationAndAttachForData(notification.waitForDebug(projectId));
168-
npc.postNotificationAndAttachForData(notification.attachRequest(projectId));
169-
});
170-
171-
awaitNotification(npc, notification.readyForAttach(projectId), this.getReadyForAttachTimeout(timeout)).wait();
172-
} catch(e) {
173-
this.$logger.trace(`Timeout error: ${e}`);
174-
this.$errors.failWithoutHelp("Timeout waiting for NativeScript debugger.");
175-
}
171+
private debugBrkCore(iosDevice: iOSDevice.IOSDevice): IFuture<void> {
172+
return (() => {
173+
let projectId = this.$projectData.projectId;
174+
let npc = new iOSProxyServices.NotificationProxyClient(iosDevice, this.$injector);
175+
176+
try {
177+
let timeout = this.$utils.getMilliSecondsTimeout(IOSDebugService.TIMEOUT_SECONDS);
178+
awaitNotification(npc, notification.appLaunching(projectId), timeout).wait();
179+
process.nextTick(() => {
180+
npc.postNotificationAndAttachForData(notification.waitForDebug(projectId));
181+
npc.postNotificationAndAttachForData(notification.attachRequest(projectId));
182+
});
183+
184+
awaitNotification(npc, notification.readyForAttach(projectId), this.getReadyForAttachTimeout(timeout)).wait();
185+
} catch(e) {
186+
this.$logger.trace(`Timeout error: ${e}`);
187+
this.$errors.failWithoutHelp("Timeout waiting for NativeScript debugger.");
188+
}
176189

177-
this.wireDebuggerClient(() => iosDevice.connectToPort(InspectorBackendPort)).wait();
178-
deploy.wait();
179-
}).future<void>()()).wait();
190+
this.wireDebuggerClient(() => iosDevice.connectToPort(InspectorBackendPort)).wait();
180191
}).future<void>()();
181192
}
182193

0 commit comments

Comments
 (0)