|
| 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 | +}); |
0 commit comments