Skip to content

Commit ea1087d

Browse files
committed
test: add tests for androidBundle
1 parent ae041ca commit ea1087d

File tree

3 files changed

+138
-2
lines changed

3 files changed

+138
-2
lines changed

lib/services/android-project-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
329329
let task;
330330
const gradleArgs = this.getGradleBuildOptions(buildConfig, projectData);
331331
const baseTask = buildConfig.androidBundle ? "bundle" : "assemble";
332-
const outputPath = buildConfig.androidBundle ? this._platformData.bundleBuildOutputPath : this._platformData.deviceBuildOutputPath;
332+
const platformData = this.getPlatformData(projectData);
333+
const outputPath = buildConfig.androidBundle ? platformData.bundleBuildOutputPath : platformData.deviceBuildOutputPath;
333334
if (this.$logger.getLevel() === "TRACE") {
334335
gradleArgs.unshift("--stacktrace");
335336
gradleArgs.unshift("--debug");
+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
});

test/stubs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ export class AndroidToolsInfoStub implements IAndroidToolsInfo {
647647
}
648648
}
649649

650-
export class ChildProcessStub {
650+
export class ChildProcessStub extends EventEmitter {
651651
public spawnCount = 0;
652652
public execCount = 0;
653653
public spawnFromEventCount = 0;

0 commit comments

Comments
 (0)