Skip to content

Commit 58ef052

Browse files
author
Tsvetan Raikov
committed
Added tests for debug + livesync
1 parent 3afa813 commit 58ef052

File tree

2 files changed

+167
-1
lines changed

2 files changed

+167
-1
lines changed

test/debug.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import * as stubs from "./stubs";
2+
import * as yok from "../lib/common/yok";
3+
import {DebugAndroidCommand} from "../lib/commands/debug";
4+
import {assert} from "chai";
5+
import {Configuration, StaticConfig} from "../lib/config";
6+
import {Options} from "../lib/options";
7+
import {DevicePlatformsConstants} from "../lib/common/mobile/device-platforms-constants";
8+
import {FileSystem} from "../lib/common/file-system";
9+
import {AndroidProjectService} from "../lib/services/android-project-service";
10+
import {AndroidDebugBridge} from "../lib/common/mobile/android/android-debug-bridge";
11+
import {AndroidDebugBridgeResultHandler} from "../lib/common/mobile/android/android-debug-bridge-result-handler";
12+
import future = require("fibers/future");
13+
14+
function createTestInjector(): IInjector {
15+
let testInjector: IInjector = new yok.Yok();
16+
17+
testInjector.register("debug|android", DebugAndroidCommand);
18+
testInjector.register("config", Configuration);
19+
testInjector.register("staticConfig", StaticConfig);
20+
testInjector.register("logger", stubs.LoggerStub);
21+
testInjector.register("options", Options);
22+
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
23+
testInjector.register('devicesService', {});
24+
testInjector.register('childProcess', stubs.ChildProcessStub);
25+
testInjector.register('androidDebugService', stubs.DebugServiceStub);
26+
testInjector.register('fs', FileSystem);
27+
testInjector.register('errors', stubs.ErrorsStub);
28+
testInjector.register('hostInfo', {});
29+
testInjector.register("analyticsService", {
30+
trackException: () => { return future.fromResult(); },
31+
checkConsent: () => { return future.fromResult(); },
32+
trackFeature: () => { return future.fromResult(); }
33+
});
34+
testInjector.register("usbLiveSyncService", stubs.LiveSyncServiceStub);
35+
testInjector.register("androidProjectService", AndroidProjectService);
36+
testInjector.register("androidToolsInfo", stubs.AndroidToolsInfoStub);
37+
testInjector.register("hostInfo", {});
38+
testInjector.register("projectData", { platformsDir: "" });
39+
testInjector.register("projectDataService", {});
40+
testInjector.register("sysInfo", {});
41+
testInjector.register("mobileHelper", {});
42+
testInjector.register("pluginVariablesService", {});
43+
testInjector.register("deviceAppDataFactory", {});
44+
testInjector.register("projectTemplatesService", {});
45+
testInjector.register("xmlValidator", {});
46+
testInjector.register("npm", {});
47+
testInjector.register("androidEmulatorServices", {});
48+
testInjector.register("adb", AndroidDebugBridge);
49+
testInjector.register("androidDebugBridgeResultHandler", AndroidDebugBridgeResultHandler);
50+
51+
return testInjector;
52+
}
53+
54+
describe("Debugger tests", () => {
55+
let testInjector: IInjector;
56+
57+
beforeEach(() => {
58+
testInjector = createTestInjector();
59+
});
60+
61+
it("Ensures that debugLivesync flag is true when executing debug --watch command", () => {
62+
let debugCommand: ICommand = testInjector.resolve("debug|android");
63+
let options: IOptions = testInjector.resolve("options");
64+
options.watch = true;
65+
debugCommand.execute(["android","--watch"]).wait();
66+
let config:IConfiguration = testInjector.resolve("config");
67+
assert.isTrue(config.debugLivesync);
68+
assert.isFalse(options.rebuild);
69+
});
70+
71+
it("Ensures that beforePrepareAllPlugins will not call gradle when livesyncing", () => {
72+
let config:IConfiguration = testInjector.resolve("config");
73+
config.debugLivesync = true;
74+
let childProcess: stubs.ChildProcessStub = testInjector.resolve("childProcess");
75+
let androidProjectService: IPlatformProjectService = testInjector.resolve("androidProjectService");
76+
let spawnFromEventCount = childProcess.spawnFromEventCount;
77+
androidProjectService.beforePrepareAllPlugins().wait();
78+
assert.isTrue(spawnFromEventCount === 0);
79+
assert.isTrue(spawnFromEventCount === childProcess.spawnFromEventCount);
80+
});
81+
82+
it("Ensures that beforePrepareAllPlugins will call gradle with clean option when *NOT* livesyncing", () => {
83+
let config:IConfiguration = testInjector.resolve("config");
84+
config.debugLivesync = false;
85+
let childProcess: stubs.ChildProcessStub = testInjector.resolve("childProcess");
86+
let androidProjectService: IPlatformProjectService = testInjector.resolve("androidProjectService");
87+
let spawnFromEventCount = childProcess.spawnFromEventCount;
88+
androidProjectService.beforePrepareAllPlugins().wait();
89+
assert.isTrue(childProcess.lastCommand === "gradle");
90+
assert.isTrue(childProcess.lastCommandArgs[0] === "clean");
91+
assert.isTrue(spawnFromEventCount === 0);
92+
assert.isTrue(spawnFromEventCount + 1 === childProcess.spawnFromEventCount);
93+
});
94+
});

test/stubs.ts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import Future = require("fibers/future");
44
import * as util from "util";
5-
65
import * as chai from "chai";
76

87
export class LoggerStub implements ILogger {
@@ -483,3 +482,76 @@ function unexpected(msg: string): Error {
483482
err.showDiff = false;
484483
return err;
485484
}
485+
486+
export class DebugServiceStub implements IDebugService {
487+
public debug(shouldBreak?: boolean): IFuture<void> {
488+
return Future.fromResult();
489+
}
490+
491+
public debugStart(): IFuture<void> {
492+
return Future.fromResult();
493+
}
494+
495+
public debugStop(): IFuture<void> {
496+
return Future.fromResult();
497+
}
498+
499+
public platform: string;
500+
}
501+
502+
export class LiveSyncServiceStub implements ILiveSyncService {
503+
public liveSync(platform: string, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): IFuture<void> {
504+
return Future.fromResult();
505+
}
506+
507+
public forceExecuteFullSync: boolean;
508+
}
509+
510+
export class AndroidToolsInfoStub implements IAndroidToolsInfo {
511+
public getToolsInfo(): IFuture<IAndroidToolsInfoData> {
512+
let infoData: IAndroidToolsInfoData = Object.create(null);
513+
infoData.androidHomeEnvVar = "";
514+
infoData.compileSdkVersion = 23;
515+
infoData.buildToolsVersion = "23";
516+
infoData.targetSdkVersion = 23;
517+
infoData.supportRepositoryVersion = "23";
518+
return Future.fromResult(infoData);
519+
}
520+
521+
public validateInfo(options?: { showWarningsAsErrors: boolean, validateTargetSdk: boolean }): IFuture<boolean> {
522+
return Future.fromResult(true);
523+
}
524+
525+
public validateJavacVersion(installedJavaVersion: string, options?: { showWarningsAsErrors: boolean }): IFuture<boolean> {
526+
return Future.fromResult(true);
527+
}
528+
529+
public getPathToAndroidExecutable(options?: { showWarningsAsErrors: boolean }): IFuture<string> {
530+
return Future.fromResult("");
531+
}
532+
533+
getPathToAdbFromAndroidHome(): IFuture<string> {
534+
return Future.fromResult("");
535+
}
536+
}
537+
538+
export class ChildProcessStub {
539+
public spawnCount = 0;
540+
public spawnFromEventCount = 0;
541+
public lastCommand = "";
542+
public lastCommandArgs: string[] = [];
543+
544+
public spawn(command: string, args?: string[], options?: any): any {
545+
this.spawnCount ++;
546+
this.lastCommand = command;
547+
this.lastCommandArgs = args;
548+
return null;
549+
}
550+
551+
public spawnFromEvent(command: string, args: string[], event: string, options?: any, spawnFromEventOptions?: ISpawnFromEventOptions): IFuture<ISpawnResult> {
552+
this.spawnFromEventCount ++;
553+
this.lastCommand = command;
554+
this.lastCommandArgs = args;
555+
return Future.fromResult(null);
556+
}
557+
}

0 commit comments

Comments
 (0)