|
| 1 | +import { IosLocalBuildRequirements } from "../lib/local-build-requirements/ios-local-build-requirements"; |
| 2 | +import { assert } from "chai"; |
| 3 | +import { HostInfo } from "../lib/host-info"; |
| 4 | +import { Constants } from "../lib/constants"; |
| 5 | + |
| 6 | +interface ITestCaseData { |
| 7 | + testName: string; |
| 8 | + expectedResult: boolean; |
| 9 | + getXcodeVersion?: string; |
| 10 | + minRequiredXcodeVersion?: number; |
| 11 | + getXcodeprojLocation?: string; |
| 12 | + isDarwin?: boolean; |
| 13 | +} |
| 14 | + |
| 15 | +describe("iOSLocalBuildRequirements", () => { |
| 16 | + const setupTestCase = (results: ITestCaseData): IosLocalBuildRequirements => { |
| 17 | + const sysInfo: NativeScriptDoctor.ISysInfo = <any>{ |
| 18 | + getXcodeVersion: async (): Promise<string> => results.hasOwnProperty("getXcodeVersion") ? results.getXcodeVersion : "10.0", |
| 19 | + getXcodeprojLocation: async (): Promise<string> => results.hasOwnProperty("getXcodeprojLocation") ? results.getXcodeprojLocation : "path to xcodeproj", |
| 20 | + }; |
| 21 | + |
| 22 | + const hostInfo: HostInfo = <any>{ |
| 23 | + isDarwin: results.hasOwnProperty("isDarwin") ? results.isDarwin : true |
| 24 | + }; |
| 25 | + |
| 26 | + const iOSLocalBuildRequirements = new IosLocalBuildRequirements(sysInfo, hostInfo); |
| 27 | + return iOSLocalBuildRequirements; |
| 28 | + }; |
| 29 | + |
| 30 | + describe("isXcodeVersionValid", () => { |
| 31 | + const testCases: ITestCaseData[] = [ |
| 32 | + { |
| 33 | + testName: "returns false when Xcode is not installed", |
| 34 | + getXcodeVersion: null, |
| 35 | + expectedResult: false |
| 36 | + }, |
| 37 | + { |
| 38 | + testName: "returns false when Xcode's major version is below min required version", |
| 39 | + getXcodeVersion: "10.0", |
| 40 | + minRequiredXcodeVersion: 11, |
| 41 | + expectedResult: false |
| 42 | + }, |
| 43 | + { |
| 44 | + testName: "returns true when Xcode's major version equals min required version", |
| 45 | + getXcodeVersion: "10.0", |
| 46 | + minRequiredXcodeVersion: 10, |
| 47 | + expectedResult: true |
| 48 | + }, |
| 49 | + { |
| 50 | + testName: "returns true when Xcode's major version equals min required version", |
| 51 | + getXcodeVersion: "12.0", |
| 52 | + minRequiredXcodeVersion: 10, |
| 53 | + expectedResult: true |
| 54 | + } |
| 55 | + ]; |
| 56 | + |
| 57 | + testCases.forEach(testCase => { |
| 58 | + it(testCase.testName, async () => { |
| 59 | + const iOSLocalBuildRequirements = setupTestCase(testCase); |
| 60 | + let originalXcodeVersion = Constants.XCODE_MIN_REQUIRED_VERSION; |
| 61 | + Constants.XCODE_MIN_REQUIRED_VERSION = testCase.minRequiredXcodeVersion || Constants.XCODE_MIN_REQUIRED_VERSION; |
| 62 | + |
| 63 | + const isXcodeVersionValid = await iOSLocalBuildRequirements.isXcodeVersionValid(); |
| 64 | + |
| 65 | + // Get back the XCODE_MIN_REQUIRED_VERSION value. |
| 66 | + Constants.XCODE_MIN_REQUIRED_VERSION = originalXcodeVersion; |
| 67 | + |
| 68 | + assert.equal(isXcodeVersionValid, testCase.expectedResult); |
| 69 | + }); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + describe("checkRequirements", () => { |
| 74 | + const testCases: ITestCaseData[] = [ |
| 75 | + { |
| 76 | + testName: "returns false when OS is not macOS", |
| 77 | + isDarwin: false, |
| 78 | + expectedResult: false |
| 79 | + }, |
| 80 | + { |
| 81 | + testName: "returns false when Xcode is not installed", |
| 82 | + getXcodeVersion: null, |
| 83 | + expectedResult: false |
| 84 | + }, |
| 85 | + { |
| 86 | + testName: "returns false when Xcode's major version is below min required version", |
| 87 | + getXcodeVersion: "10.0", |
| 88 | + minRequiredXcodeVersion: 11, |
| 89 | + expectedResult: false |
| 90 | + }, |
| 91 | + { |
| 92 | + testName: "returns false when xcodeproj is not installed", |
| 93 | + getXcodeprojLocation: null, |
| 94 | + expectedResult: false |
| 95 | + }, |
| 96 | + { |
| 97 | + testName: "returns true when Xcode's major version equals min required version", |
| 98 | + getXcodeVersion: "10.0", |
| 99 | + minRequiredXcodeVersion: 10, |
| 100 | + expectedResult: true |
| 101 | + }, |
| 102 | + { |
| 103 | + testName: "returns true when Xcode's major version equals min required version", |
| 104 | + getXcodeVersion: "12.0", |
| 105 | + minRequiredXcodeVersion: 10, |
| 106 | + expectedResult: true |
| 107 | + } |
| 108 | + ]; |
| 109 | + |
| 110 | + testCases.forEach(testCase => { |
| 111 | + it(testCase.testName, async () => { |
| 112 | + const iOSLocalBuildRequirements = setupTestCase(testCase); |
| 113 | + let originalXcodeVersion = Constants.XCODE_MIN_REQUIRED_VERSION; |
| 114 | + Constants.XCODE_MIN_REQUIRED_VERSION = testCase.minRequiredXcodeVersion || Constants.XCODE_MIN_REQUIRED_VERSION; |
| 115 | + |
| 116 | + const isXcodeVersionValid = await iOSLocalBuildRequirements.checkRequirements(); |
| 117 | + |
| 118 | + // Get back the XCODE_MIN_REQUIRED_VERSION value. |
| 119 | + Constants.XCODE_MIN_REQUIRED_VERSION = originalXcodeVersion; |
| 120 | + |
| 121 | + assert.equal(isXcodeVersionValid, testCase.expectedResult); |
| 122 | + }); |
| 123 | + }); |
| 124 | + }); |
| 125 | +}); |
0 commit comments