|
| 1 | +import { AndroidProjectService } from "../../lib/services/android-project-service"; |
| 2 | +import { Yok } from "../../lib/common/yok"; |
| 3 | +import * as stubs from "../stubs"; |
| 4 | +import { assert } from "chai"; |
| 5 | +import * as sinon from "sinon"; |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +const createTestInjector = (): IInjector => { |
| 10 | + const testInjector = new Yok(); |
| 11 | + testInjector.register("androidProjectService", AndroidProjectService); |
| 12 | + testInjector.register("childProcess", stubs.ChildProcessStub); |
| 13 | + testInjector.register("hostInfo", {}); |
| 14 | + testInjector.register("projectDataService", stubs.ProjectDataService); |
| 15 | + testInjector.register("pluginVariablesService", {}); |
| 16 | + testInjector.register("fs", stubs.FileSystemStub); |
| 17 | + testInjector.register("injector", testInjector); |
| 18 | + testInjector.register("devicePlatformsConstants", {}); |
| 19 | + testInjector.register("npm", {}); |
| 20 | + testInjector.register("platformEnvironmentRequirements", {}); |
| 21 | + testInjector.register("androidResourcesMigrationService", {}); |
| 22 | + testInjector.register("androidPluginBuildService", {}); |
| 23 | + testInjector.register("filesHashService", { |
| 24 | + saveHashesForProject: () => {} |
| 25 | + }); |
| 26 | + testInjector.register("androidPluginBuildService", {}); |
| 27 | + testInjector.register("errors", stubs.ErrorsStub); |
| 28 | + testInjector.register("logger", stubs.LoggerStub); |
| 29 | + testInjector.register("projectData", stubs.ProjectDataStub); |
| 30 | + testInjector.register("androidToolsInfo", { |
| 31 | + getToolsInfo: () => { |
| 32 | + return { |
| 33 | + androidHomeEnvVar: true |
| 34 | + }; |
| 35 | + }, |
| 36 | + validateInfo: () => { |
| 37 | + |
| 38 | + } |
| 39 | + }); |
| 40 | + |
| 41 | + return testInjector; |
| 42 | +}; |
| 43 | + |
| 44 | +const getDefautlBuildConfig = (): IBuildConfig => { |
| 45 | + return { |
| 46 | + release: true, |
| 47 | + buildForDevice: false, |
| 48 | + device: "testDevice", |
| 49 | + provision: null, |
| 50 | + teamId: "", |
| 51 | + projectDir: "location/location", |
| 52 | + keyStorePath: "" |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +describe.only("androidDebugService", () => { |
| 57 | + let injector: IInjector; |
| 58 | + let androidProjectService: IPlatformProjectService; |
| 59 | + let sandbox: sinon.SinonSandbox = null; |
| 60 | + |
| 61 | + beforeEach(() => { |
| 62 | + sandbox = sinon.sandbox.create(); |
| 63 | + injector = createTestInjector(); |
| 64 | + androidProjectService = injector.resolve("androidProjectService"); |
| 65 | + }); |
| 66 | + |
| 67 | + afterEach(() => { |
| 68 | + sandbox.restore(); |
| 69 | + }); |
| 70 | + |
| 71 | + describe("buildPlatform", () => { |
| 72 | + let projectData: IProjectData; |
| 73 | + let childProcess: stubs.ChildProcessStub; |
| 74 | + |
| 75 | + beforeEach(() => { |
| 76 | + projectData = injector.resolve("projectData"); |
| 77 | + childProcess = injector.resolve("childProcess"); |
| 78 | + const getPlatformDataStub: sinon.SinonStub = sandbox.stub(androidProjectService, "getPlatformData"); |
| 79 | + getPlatformDataStub.callsFake(() => { |
| 80 | + return { |
| 81 | + configurationFilePath: "" |
| 82 | + }; |
| 83 | + }); |
| 84 | + |
| 85 | + }); |
| 86 | + |
| 87 | + it("release no bundle", async () => { |
| 88 | + //arrange |
| 89 | + const buildConfig = getDefautlBuildConfig(); |
| 90 | + |
| 91 | + //act |
| 92 | + await androidProjectService.buildProject("local/local", projectData, buildConfig, ); |
| 93 | + |
| 94 | + //assert |
| 95 | + assert.include(childProcess.lastCommandArgs, "assembleRelease"); |
| 96 | + }) |
| 97 | + |
| 98 | + it("debug no bundle", async () => { |
| 99 | + //arrange |
| 100 | + const buildConfig = getDefautlBuildConfig(); |
| 101 | + buildConfig.release = false; |
| 102 | + |
| 103 | + //act |
| 104 | + await androidProjectService.buildProject("local/local", projectData, buildConfig, ); |
| 105 | + |
| 106 | + //assert |
| 107 | + assert.include(childProcess.lastCommandArgs, "assembleDebug"); |
| 108 | + }) |
| 109 | + |
| 110 | + it("release bundle", async () => { |
| 111 | + //arrange |
| 112 | + const buildConfig = getDefautlBuildConfig(); |
| 113 | + buildConfig.androidBundle = true; |
| 114 | + |
| 115 | + //act |
| 116 | + await androidProjectService.buildProject("local/local", projectData, buildConfig, ); |
| 117 | + |
| 118 | + //assert |
| 119 | + assert.include(childProcess.lastCommandArgs, "bundleRelease"); |
| 120 | + }) |
| 121 | + |
| 122 | + it("debug bundle", async () => { |
| 123 | + //arrange |
| 124 | + const buildConfig = getDefautlBuildConfig(); |
| 125 | + buildConfig.androidBundle = true; |
| 126 | + buildConfig.release = false; |
| 127 | + |
| 128 | + //act |
| 129 | + await androidProjectService.buildProject("local/local", projectData, buildConfig, ); |
| 130 | + |
| 131 | + //assert |
| 132 | + assert.include(childProcess.lastCommandArgs, "bundleDebug"); |
| 133 | + }) |
| 134 | + }); |
| 135 | +}); |
0 commit comments