Skip to content

Commit 82f5c5a

Browse files
committed
fix: failing tests
1 parent aea3714 commit 82f5c5a

10 files changed

+39
-31
lines changed

lib/services/android-plugin-build-service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
181181
const androidSourceDirectories = this.getAndroidSourceDirectories(options.platformsAndroidDirPath);
182182
const shortPluginName = getShortPluginName(options.pluginName);
183183
const pluginTempDir = path.join(options.tempPluginDirPath, shortPluginName);
184-
const pluginSourceFileHashesInfo = await this.getSourceFilesHashes(options.platformsAndroidDirPath, shortPluginName);
184+
const pluginSourceFileHashesInfo = await this.getSourceFilesHashes(options.platformsAndroidDirPath, shortPluginName);
185185

186186
const shouldBuildAar = await this.shouldBuildAar({
187187
manifestFilePath,
@@ -190,7 +190,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
190190
pluginSourceDir: options.platformsAndroidDirPath,
191191
shortPluginName,
192192
fileHashesInfo: pluginSourceFileHashesInfo
193-
});
193+
});
194194

195195
if (shouldBuildAar) {
196196
this.cleanPluginDir(pluginTempDir);
@@ -308,11 +308,11 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
308308
const platformData = this.$platformsDataService.getPlatformData(this.$devicePlatformsConstants.Android, projectData);
309309
const projectRuntimeVersion = platformData.platformProjectService.getFrameworkVersion(projectData);
310310
this.$logger.trace(`Got gradle versions ${JSON.stringify(runtimeGradleVersions)} from runtime v${projectRuntimeVersion}`);
311-
}
312-
313-
const runtimePackage = this.$projectDataService.getRuntimePackage(projectDir, PlatformTypes.android);
311+
}
312+
314313

315314
if (!runtimeGradleVersions) {
315+
const runtimePackage = this.$projectDataService.getRuntimePackage(projectDir, PlatformTypes.android);
316316
const latestRuntimeVersion = await this.getLatestRuntimeVersion(runtimePackage);
317317
runtimeGradleVersions = await this.getGradleVersions(latestRuntimeVersion, runtimePackage);
318318
this.$logger.trace(`Got gradle versions ${JSON.stringify(runtimeGradleVersions)} from the latest runtime v${latestRuntimeVersion}`);

lib/services/pacote-service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ export class PacoteService implements IPacoteService {
5959
});
6060

6161
this.$logger.trace(`Creating extract tar stream with options: ${JSON.stringify(extractOptions, null, 2)}`);
62-
const destination = tar.x(extractOptions);
63-
// Initiate the source
64-
const sourceStream = new PassThrough();
65-
sourceStream.end(source);
66-
sourceStream.pipe(destination);
62+
const destination = tar.x(extractOptions);
63+
// Initiate the source
64+
const sourceStream = new PassThrough();
65+
sourceStream.end(source);
66+
sourceStream.pipe(destination);
6767

6868
destination.on("error", (err: Error) => {
6969
this.$logger.trace(`Error in destination while trying to extract stream from ${packageName}. Error is ${err}`);

test/controllers/update-controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function createTestInjector(
5555
testInjector.register("packageInstallationManager", stubs.PackageInstallationManagerStub);
5656
testInjector.register("platformsDataService", stubs.NativeProjectDataStub);
5757
testInjector.register("pacoteService", stubs.PacoteServiceStub);
58-
testInjector.register("projectDataService", stubs.ProjectDataService);
58+
testInjector.register("projectDataService", stubs.ProjectDataServiceStub);
5959
testInjector.register("updateController", UpdateController);
6060

6161
return testInjector;
@@ -200,4 +200,4 @@ describe("update controller method tests", () => {
200200
// });
201201
// });
202202
// }
203-
});
203+
});

test/ios-project-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { YarnPackageManager } from "../lib/yarn-package-manager";
3131
import { assert } from "chai";
3232
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
3333
import { BUILD_XCCONFIG_FILE_NAME } from "../lib/constants";
34-
import { ProjectDataStub, TempServiceStub, ProjectDataService } from "./stubs";
34+
import { ProjectDataStub, TempServiceStub, ProjectDataServiceStub } from "./stubs";
3535
import { xcode } from "../lib/node/xcode";
3636
import temp = require("temp");
3737
import { CocoaPodsPlatformManager } from "../lib/services/cocoapods-platform-manager";
@@ -97,7 +97,7 @@ function createTestInjector(projectPath: string, projectName: string, xCode?: IX
9797
testInjector.register("projectHelper", {});
9898
testInjector.register("xcodeSelectService", {});
9999
testInjector.register("staticConfig", ConfigLib.StaticConfig);
100-
testInjector.register("projectDataService", ProjectDataService);
100+
testInjector.register("projectDataService", ProjectDataServiceStub);
101101
testInjector.register("prompter", {});
102102
testInjector.register("devicePlatformsConstants", { iOS: "iOS" });
103103
testInjector.register("devicesService", DevicesService);

test/platform-commands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function createTestInjector() {
122122
testInjector.register('projectData', stubs.ProjectDataStub);
123123
testInjector.register('platformsDataService', PlatformsDataService);
124124
testInjector.register('devicesService', {});
125-
testInjector.register('projectDataService', stubs.ProjectDataService);
125+
testInjector.register('projectDataService', stubs.ProjectDataServiceStub);
126126
testInjector.register('prompter', {});
127127
testInjector.register('sysInfo', {});
128128
testInjector.register('commands-service', CommandsServiceLib.CommandsService);

test/services/android-plugin-build-service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ describe('androidPluginBuildService', () => {
119119
view: async (packageName: string, config: any): Promise<any> => {
120120
let result: any = null;
121121
if (config && config.gradle) {
122-
const packageVersion = packageName.split("@")[1];
122+
const packageNameParts = packageName.split("@");
123+
const packageVersion = packageNameParts[packageNameParts.length - 1];
123124
switch (packageVersion) {
124125
case "1.0.0":
125126
result = {
@@ -316,7 +317,7 @@ dependencies {
316317
assert.isTrue(spawnFromEventCalled);
317318
});
318319

319-
it.skip('builds aar with the specified runtime gradle versions when the project runtime has gradle versions', async () => {
320+
it('builds aar with the specified runtime gradle versions when the project runtime has gradle versions', async () => {
320321
const expectedGradleVersion = "4.4.4";
321322
const expectedAndroidVersion = "5.5.5";
322323
const config: IPluginBuildOptions = setup({

test/services/android-project-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const createTestInjector = (): IInjector => {
1818
testInjector.register("hooksService", stubs.HooksServiceStub);
1919
testInjector.register("childProcess", stubs.ChildProcessStub);
2020
testInjector.register("hostInfo", {});
21-
testInjector.register("projectDataService", stubs.ProjectDataService);
21+
testInjector.register("projectDataService", stubs.ProjectDataServiceStub);
2222
testInjector.register("pluginVariablesService", {});
2323
testInjector.register("fs", stubs.FileSystemStub);
2424
testInjector.register("injector", testInjector);

test/services/pacote-service.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,33 @@ class MockStream extends EventEmitter {
9090
public pipe(destination: any, options?: { end?: boolean; }): any {
9191
// Nothing to do here, just mock the method.
9292
}
93+
public end(): any {
94+
//
95+
}
96+
}
97+
98+
class MockBuffer {
99+
constructor() {
100+
return Buffer.from([]);
101+
}
93102
}
94103

95-
describe.skip("pacoteService", () => {
104+
describe("pacoteService", () => {
96105
const manifestResult: any = {};
97106
const manifestOptions: IPacoteManifestOptions = { fullMetadata: true };
98107
let sandboxInstance: sinon.SinonSandbox = null;
99108
let manifestStub: sinon.SinonStub = null;
100109
let tarballStreamStub: sinon.SinonStub = null;
101110
let tarXStub: sinon.SinonStub = null;
102-
let tarballSourceStream: MockStream = null;
111+
let tarballSourceBuffer: MockBuffer = null;
103112
let tarExtractDestinationStream: MockStream = null;
104113

105114
beforeEach(() => {
106115
sandboxInstance = sinon.createSandbox();
107116
manifestStub = sandboxInstance.stub(pacote, "manifest").returns(Promise.resolve(manifestResult));
108-
tarballSourceStream = new MockStream();
109-
tarballStreamStub = sandboxInstance.stub(pacote, "tarball").returns(Promise.resolve(<any>tarballSourceStream));
110-
tarExtractDestinationStream = new MockStream();
117+
tarballSourceBuffer = new MockBuffer();
118+
tarballStreamStub = sandboxInstance.stub(pacote, "tarball").returns(Promise.resolve(<any>tarballSourceBuffer));
119+
tarExtractDestinationStream = new MockStream();
111120
tarXStub = sandboxInstance.stub(tar, "x").returns(<any>tarExtractDestinationStream);
112121
});
113122

@@ -205,13 +214,11 @@ describe.skip("pacoteService", () => {
205214
});
206215

207216
describe("extractPackage", () => {
208-
it("fails with correct error when pacote.tarball.stream raises error event", async () => {
217+
it("fails with correct error when pacote.tarball raises error event", async () => {
209218
const pacoteService = setupTest();
210219

220+
tarballStreamStub.returns(Promise.reject(new Error(errorMessage)));
211221
const pacoteExtractPackagePromise = pacoteService.extractPackage(packageName, destinationDir);
212-
setImmediate(() => {
213-
tarballSourceStream.emit("error", new Error(errorMessage));
214-
});
215222

216223
await assert.isRejected(pacoteExtractPackagePromise, errorMessage);
217224
});

test/stubs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ export class NativeProjectDataStub extends EventEmitter implements IPlatformsDat
632632
}
633633
}
634634

635-
export class ProjectDataService implements IProjectDataService {
635+
export class ProjectDataServiceStub implements IProjectDataService {
636636
getNSValue(propertyName: string): any {
637637
return {};
638638
}
@@ -1042,7 +1042,7 @@ export class InjectorStub extends Yok implements IInjector {
10421042
this.register("config", {});
10431043
this.register("staticConfig", {});
10441044
this.register("hooksService", HooksServiceStub);
1045-
this.register('projectDataService', ProjectDataService);
1045+
this.register('projectDataService', ProjectDataServiceStub);
10461046
this.register('devicePlatformsConstants', DevicePlatformsConstants);
10471047
this.register("androidResourcesMigrationService", AndroidResourcesMigrationServiceStub);
10481048
this.register("commandsService", CommandsService);

test/tns-appstore-upload.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PublishIOS } from "../lib/commands/appstore-upload";
2-
import { PrompterStub, LoggerStub, ProjectDataStub, ProjectDataService } from "./stubs";
2+
import { PrompterStub, LoggerStub, ProjectDataStub, ProjectDataServiceStub } from "./stubs";
33
import * as chai from "chai";
44
import * as yok from "../lib/common/yok";
55
import { PrepareNativePlatformService } from "../lib/services/platform/prepare-native-platform-service";
@@ -99,7 +99,7 @@ class AppStore {
9999
}
100100
}
101101

102-
this.injector.register("projectDataService", ProjectDataService);
102+
this.injector.register("projectDataService", ProjectDataServiceStub);
103103
}
104104

105105
assert() {

0 commit comments

Comments
 (0)