Skip to content

Commit d95caad

Browse files
refactor: pass object instead of boolean to verifyXcproj method
1 parent aa79341 commit d95caad

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

lib/declarations.d.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -773,17 +773,27 @@ interface IProjectNameService {
773773
ensureValidName(projectName: string, validateOptions?: { force: boolean }): Promise<string>;
774774
}
775775

776+
/**
777+
* Describes options that can be passed to xcprojService.verifyXcproj method.
778+
*/
779+
interface IVerifyXcprojOptions {
780+
/**
781+
* Whether to fail with error message or not
782+
*/
783+
shouldFail: boolean;
784+
}
785+
776786
/**
777787
* Designed for getting information about xcproj.
778788
*/
779789
interface IXcprojService {
780790
/**
781791
* Checks whether the system needs xcproj to execute ios builds successfully.
782792
* In case the system does need xcproj but does not have it, prints an error message.
783-
* @param {boolean} whether to fail with error message or not
793+
* @param {IVerifyXcprojOptions} opts whether to fail with error message or not
784794
* @return {Promise<boolean>} whether an error occurred or not.
785795
*/
786-
verifyXcproj(shouldFail: boolean): Promise<boolean>;
796+
verifyXcproj(opts: IVerifyXcprojOptions): Promise<boolean>;
787797
/**
788798
* Collects information about xcproj.
789799
* @return {Promise<XcprojInfo>} collected info about xcproj.
@@ -903,4 +913,4 @@ interface IRuntimeGradleVersions {
903913

904914
interface INetworkConnectivityValidator {
905915
validate(): Promise<void>;
906-
}
916+
}

lib/services/cocoapods-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class CocoaPodsService implements ICocoaPodsService {
3434
this.$errors.failWithoutHelp("CocoaPods or ruby gem 'xcodeproj' is not installed. Run `sudo gem install cocoapods` and try again.");
3535
}
3636

37-
await this.$xcprojService.verifyXcproj(true);
37+
await this.$xcprojService.verifyXcproj({ shouldFail: true });
3838

3939
this.$logger.info("Installing pods...");
4040
const podTool = this.$config.USE_POD_SANDBOX ? "sandbox-pod" : "pod";

lib/services/xcproj-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class XcprojService implements IXcprojService {
1212
private $xcodeSelectService: IXcodeSelectService) {
1313
}
1414

15-
public async verifyXcproj(shouldFail: boolean): Promise<boolean> {
15+
public async verifyXcproj(opts: IVerifyXcprojOptions): Promise<boolean> {
1616
const xcprojInfo = await this.getXcprojInfo();
1717
if (xcprojInfo.shouldUseXcproj && !xcprojInfo.xcprojAvailable) {
1818
const errorMessage = `You are using CocoaPods version ${xcprojInfo.cocoapodVer} which does not support Xcode ${xcprojInfo.xcodeVersion.major}.${xcprojInfo.xcodeVersion.minor} yet.${EOL}${EOL}You can update your cocoapods by running $sudo gem install cocoapods from a terminal.${EOL}${EOL}In order for the NativeScript CLI to be able to work correctly with this setup you need to install xcproj command line tool and add it to your PATH. Xcproj can be installed with homebrew by running $ brew install xcproj from the terminal`;
19-
if (shouldFail) {
19+
if (opts.shouldFail) {
2020
this.$errors.failWithoutHelp(errorMessage);
2121
} else {
2222
this.$logger.warn(errorMessage);

test/cocoapods-service.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ end`
697697
});
698698

699699
const xcprojService = testInjector.resolve<IXcprojService>("xcprojService");
700-
xcprojService.verifyXcproj = async (shouldFail: boolean): Promise<boolean> => false;
700+
xcprojService.verifyXcproj = async (opts: IVerifyXcprojOptions): Promise<boolean> => false;
701701
xcprojService.getXcprojInfo = async (): Promise<IXcprojInfo> => (<any>{});
702702
});
703703

@@ -729,7 +729,7 @@ end`
729729
it("fails with correct error when xcprojService.verifyXcproj throws", async () => {
730730
const expectedError = new Error("err");
731731
const xcprojService = testInjector.resolve<IXcprojService>("xcprojService");
732-
xcprojService.verifyXcproj = async (shouldFail: boolean): Promise<boolean> => {
732+
xcprojService.verifyXcproj = async (opts: IVerifyXcprojOptions): Promise<boolean> => {
733733
throw expectedError;
734734
};
735735

@@ -756,6 +756,18 @@ end`
756756
});
757757
});
758758

759+
it("calls xcprojService.verifyXcproj with correct arguments", async () => {
760+
const xcprojService = testInjector.resolve<IXcprojService>("xcprojService");
761+
let optsPassedToVerifyXcproj: any = null;
762+
xcprojService.verifyXcproj = async (opts: IVerifyXcprojOptions): Promise<boolean> => {
763+
optsPassedToVerifyXcproj = opts;
764+
return false;
765+
};
766+
767+
await cocoapodsService.executePodInstall(projectRoot, xcodeProjPath);
768+
assert.deepEqual(optsPassedToVerifyXcproj, { shouldFail: true });
769+
});
770+
759771
it("calls pod install spawnFromEvent with correct arguments", async () => {
760772
const childProcess = testInjector.resolve<IChildProcess>("childProcess");
761773
let commandCalled = "";

0 commit comments

Comments
 (0)