1- import * as fs from "fs" ;
2- import * as child from "child_process" ;
1+ import fs from "fs" ;
2+ import child from "child_process" ;
33import * as core from "@actions/core" ;
4- import { XcodeSelector , XcodeVersion } from "../src/xcode-selector" ;
4+ import { XcodeSelector } from "../src/xcode-selector" ;
55import * as xcodeUtils from "../src/xcode-utils" ;
66
7- jest . mock ( "fs" ) ;
87jest . mock ( "child_process" ) ;
9- jest . mock ( "@actions/core" ) ;
10- jest . mock ( "../src/xcode-utils" ) ;
118
12- const buildFsDirentItem = ( name : string , opt : { isSymbolicLink : boolean ; isDirectory : boolean } ) : fs . Dirent => {
13- return {
14- name,
15- isSymbolicLink : ( ) => opt . isSymbolicLink ,
16- isDirectory : ( ) => opt . isDirectory
17- } as fs . Dirent ;
18- } ;
19-
20- const fakeReadDirResults = [
21- buildFsDirentItem ( "Xcode.app" , { isSymbolicLink : true , isDirectory : false } ) ,
22- buildFsDirentItem ( "Xcode.app" , { isSymbolicLink : false , isDirectory : true } ) ,
23- buildFsDirentItem ( "Xcode_11.1.app" , { isSymbolicLink : false , isDirectory : true } ) ,
24- buildFsDirentItem ( "Xcode_11.1_beta.app" , { isSymbolicLink : true , isDirectory : false } ) ,
25- buildFsDirentItem ( "Xcode_11.2.1.app" , { isSymbolicLink : false , isDirectory : true } ) ,
26- buildFsDirentItem ( "Xcode_11.4.app" , { isSymbolicLink : true , isDirectory : false } ) ,
27- buildFsDirentItem ( "Xcode_11.4_beta.app" , { isSymbolicLink : false , isDirectory : true } ) ,
28- buildFsDirentItem ( "Xcode_11.app" , { isSymbolicLink : false , isDirectory : true } ) ,
29- buildFsDirentItem ( "Xcode_12_beta.app" , { isSymbolicLink : false , isDirectory : true } ) ,
30- buildFsDirentItem ( "third_party_folder" , { isSymbolicLink : false , isDirectory : true } ) ,
9+ const fakeGetXcodeVersionInfoResult : xcodeUtils . XcodeVersion [ ] = [
10+ { version : "10.3.0" , buildNumber : "" , path : "/Applications/Xcode_10.3.app" , releaseType : "GM" , stable : true } ,
11+ { version : "12.0.0" , buildNumber : "" , path : "/Applications/Xcode_12_beta.app" , releaseType : "Beta" , stable : false } ,
12+ { version : "11.2.1" , buildNumber : "" , path : "/Applications/Xcode_11.2.1.app" , releaseType : "GM" , stable : true } ,
13+ { version : "11.4.0" , buildNumber : "" , path : "/Applications/Xcode_11.4.app" , releaseType : "GM" , stable : true } ,
14+ { version : "11.0.0" , buildNumber : "" , path : "/Applications/Xcode_11.app" , releaseType : "GM" , stable : true } ,
15+ { version : "11.2.0" , buildNumber : "" , path : "/Applications/Xcode_11.2.app" , releaseType : "GM" , stable : true } ,
3116] ;
32-
33- const fakeGetVersionsResult : XcodeVersion [ ] = [
34- { version : "12.0.0" , path : "" , stable : false } ,
35- { version : "11.4.0" , path : "" , stable : true } ,
36- { version : "11.2.1" , path : "" , stable : true } ,
37- { version : "11.2.0" , path : "" , stable : true } ,
38- { version : "11.0.0" , path : "" , stable : true } ,
39- { version : "10.3.0" , path : "" , stable : true }
17+ const fakeGetInstalledXcodeAppsResult : string [ ] = [
18+ "/Applications/Xcode_10.3.app" ,
19+ "/Applications/Xcode_12_beta.app" ,
20+ "/Applications/Xcode_11.2.1.app" ,
21+ "/Applications/Xcode_11.4.app" ,
22+ "/Applications/Xcode_11.app" ,
23+ "/Applications/Xcode_11.2.app" ,
24+ "/Applications/Xcode_fake_path.app"
25+ ] ;
26+ const expectedGetAllVersionsResult : xcodeUtils . XcodeVersion [ ] = [
27+ { version : "12.0.0" , buildNumber : "" , path : "/Applications/Xcode_12_beta.app" , releaseType : "Beta" , stable : false } ,
28+ { version : "11.4.0" , buildNumber : "" , path : "/Applications/Xcode_11.4.app" , releaseType : "GM" , stable : true } ,
29+ { version : "11.2.1" , buildNumber : "" , path : "/Applications/Xcode_11.2.1.app" , releaseType : "GM" , stable : true } ,
30+ { version : "11.2.0" , buildNumber : "" , path : "/Applications/Xcode_11.2.app" , releaseType : "GM" , stable : true } ,
31+ { version : "11.0.0" , buildNumber : "" , path : "/Applications/Xcode_11.app" , releaseType : "GM" , stable : true } ,
32+ { version : "10.3.0" , buildNumber : "" , path : "/Applications/Xcode_10.3.app" , releaseType : "GM" , stable : true } ,
4033] ;
4134
4235describe ( "XcodeSelector" , ( ) => {
43- describe ( "getXcodeVersionFromAppPath" , ( ) => {
44- beforeEach ( ( ) => {
45- jest . spyOn ( xcodeUtils , "getXcodeReleaseType" ) . mockImplementation ( ( ) => xcodeUtils . XcodeReleaseType . GM ) ;
46- } ) ;
47-
48- afterEach ( ( ) => {
49- jest . resetAllMocks ( ) ;
50- jest . clearAllMocks ( ) ;
51- } ) ;
52-
53- it . each ( [
54- [ "/temp/Xcode_11.app" , { version : "11.0.0" , path : "/temp/Xcode_11.app" , stable : true } ] ,
55- [ "/temp/Xcode_11.2.app" , { version : "11.2.0" , path : "/temp/Xcode_11.2.app" , stable : true } ] ,
56- [ "/temp/Xcode_11.2.1.app" , { version : "11.2.1" , path : "/temp/Xcode_11.2.1.app" , stable : true } ] ,
57- [ "/temp/Xcode_11.2.1_beta.app" , { version : "11.2.1" , path : "/temp/Xcode_11.2.1_beta.app" , stable : true } ] ,
58- [ "/temp/Xcode.app" , null ] ,
59- [ "/temp/Xcode_11.2" , null ] ,
60- [ "/temp/Xcode.11.2.app" , null ]
61- ] ) ( "'%s' -> '%s'" , ( input : string , expected : XcodeVersion | null ) => {
62- // test private method
63- const actual = new XcodeSelector ( ) [ "getXcodeVersionFromAppPath" ] ( input ) ;
64- expect ( actual ) . toEqual ( expected ) ;
65- } ) ;
66-
67- } ) ;
68-
6936 describe ( "getAllVersions" , ( ) => {
7037 beforeEach ( ( ) => {
71- jest . spyOn ( fs , "readdirSync " ) . mockImplementation ( ( ) => fakeReadDirResults ) ;
72- jest . spyOn ( xcodeUtils , "getXcodeReleaseType " ) . mockImplementation ( ( ) => xcodeUtils . XcodeReleaseType . GM ) ;
38+ jest . spyOn ( xcodeUtils , "getInstalledXcodeApps " ) . mockImplementation ( ( ) => fakeGetInstalledXcodeAppsResult ) ;
39+ jest . spyOn ( xcodeUtils , "getXcodeVersionInfo " ) . mockImplementation ( ( path ) => fakeGetXcodeVersionInfoResult . find ( app => app . path === path ) ?? null ) ;
7340 } ) ;
7441
7542 afterEach ( ( ) => {
@@ -79,14 +46,7 @@ describe("XcodeSelector", () => {
7946
8047 it ( "versions are filtered correctly" , ( ) => {
8148 const sel = new XcodeSelector ( ) ;
82- const expectedVersions : XcodeVersion [ ] = [
83- { version : "12.0.0" , path : "/Applications/Xcode_12_beta.app" , stable : true } ,
84- { version : "11.4.0" , path : "/Applications/Xcode_11.4_beta.app" , stable : true } ,
85- { version : "11.2.1" , path : "/Applications/Xcode_11.2.1.app" , stable : true } ,
86- { version : "11.1.0" , path : "/Applications/Xcode_11.1.app" , stable : true } ,
87- { version : "11.0.0" , path : "/Applications/Xcode_11.app" , stable : true } ,
88- ] ;
89- expect ( sel . getAllVersions ( ) ) . toEqual ( expectedVersions ) ;
49+ expect ( sel . getAllVersions ( ) ) . toEqual ( expectedGetAllVersionsResult ) ;
9050 } ) ;
9151 } ) ;
9252
@@ -106,7 +66,7 @@ describe("XcodeSelector", () => {
10666 [ "give me latest version" , null ]
10767 ] as [ string , string | null ] [ ] ) ( "'%s' -> '%s'" , ( versionSpec : string , expected : string | null ) => {
10868 const sel = new XcodeSelector ( ) ;
109- sel . getAllVersions = ( ) : XcodeVersion [ ] => fakeGetVersionsResult ;
69+ sel . getAllVersions = ( ) : xcodeUtils . XcodeVersion [ ] => expectedGetAllVersionsResult ;
11070 const matchedVersion = sel . findVersion ( versionSpec ) ?. version ?? null ;
11171 expect ( matchedVersion ) . toBe ( expected ) ;
11272 } ) ;
@@ -116,8 +76,10 @@ describe("XcodeSelector", () => {
11676 let coreExportVariableSpy : jest . SpyInstance ;
11777 let fsExistsSpy : jest . SpyInstance ;
11878 let fsSpawnSpy : jest . SpyInstance ;
119- const xcodeVersion : XcodeVersion = {
79+ const xcodeVersion : xcodeUtils . XcodeVersion = {
12080 version : "11.4" ,
81+ buildNumber : "12A7300" ,
82+ releaseType : "GM" ,
12183 path : "/Applications/Xcode_11.4.app" ,
12284 stable : true
12385 } ;
0 commit comments