1
- import * as fs from "fs" ;
2
- import * as child from "child_process" ;
1
+ import fs from "fs" ;
2
+ import child from "child_process" ;
3
3
import * as core from "@actions/core" ;
4
- import { XcodeSelector , XcodeVersion } from "../src/xcode-selector" ;
4
+ import { XcodeSelector } from "../src/xcode-selector" ;
5
5
import * as xcodeUtils from "../src/xcode-utils" ;
6
6
7
- jest . mock ( "fs" ) ;
8
7
jest . mock ( "child_process" ) ;
9
- jest . mock ( "@actions/core" ) ;
10
- jest . mock ( "../src/xcode-utils" ) ;
11
8
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 } ,
31
16
] ;
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 } ,
40
33
] ;
41
34
42
35
describe ( "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
-
69
36
describe ( "getAllVersions" , ( ) => {
70
37
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 ) ;
73
40
} ) ;
74
41
75
42
afterEach ( ( ) => {
@@ -79,14 +46,7 @@ describe("XcodeSelector", () => {
79
46
80
47
it ( "versions are filtered correctly" , ( ) => {
81
48
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 ) ;
90
50
} ) ;
91
51
} ) ;
92
52
@@ -106,7 +66,7 @@ describe("XcodeSelector", () => {
106
66
[ "give me latest version" , null ]
107
67
] as [ string , string | null ] [ ] ) ( "'%s' -> '%s'" , ( versionSpec : string , expected : string | null ) => {
108
68
const sel = new XcodeSelector ( ) ;
109
- sel . getAllVersions = ( ) : XcodeVersion [ ] => fakeGetVersionsResult ;
69
+ sel . getAllVersions = ( ) : xcodeUtils . XcodeVersion [ ] => expectedGetAllVersionsResult ;
110
70
const matchedVersion = sel . findVersion ( versionSpec ) ?. version ?? null ;
111
71
expect ( matchedVersion ) . toBe ( expected ) ;
112
72
} ) ;
@@ -116,8 +76,10 @@ describe("XcodeSelector", () => {
116
76
let coreExportVariableSpy : jest . SpyInstance ;
117
77
let fsExistsSpy : jest . SpyInstance ;
118
78
let fsSpawnSpy : jest . SpyInstance ;
119
- const xcodeVersion : XcodeVersion = {
79
+ const xcodeVersion : xcodeUtils . XcodeVersion = {
120
80
version : "11.4" ,
81
+ buildNumber : "12A7300" ,
82
+ releaseType : "GM" ,
121
83
path : "/Applications/Xcode_11.4.app" ,
122
84
stable : true
123
85
} ;
0 commit comments