@@ -10,6 +10,7 @@ import * as StaticConfigLib from "../lib/config";
10
10
import * as yok from "../lib/common/yok" ;
11
11
import ChildProcessLib = require( "../lib/common/child-process" ) ;
12
12
import { SettingsService } from "../lib/common/test/unit-tests/stubs" ;
13
+ import { ProjectDataService } from "../lib/services/project-data-service" ;
13
14
14
15
function createTestInjector ( ) : IInjector {
15
16
const testInjector = new yok . Yok ( ) ;
@@ -23,6 +24,7 @@ function createTestInjector(): IInjector {
23
24
testInjector . register ( "staticConfig" , StaticConfigLib . StaticConfig ) ;
24
25
testInjector . register ( "childProcess" , ChildProcessLib . ChildProcess ) ;
25
26
testInjector . register ( "settingsService" , SettingsService ) ;
27
+ testInjector . register ( "projectDataService" , ProjectDataService ) ;
26
28
27
29
testInjector . register ( "npmInstallationManager" , NpmInstallationManagerLib . NpmInstallationManager ) ;
28
30
@@ -57,121 +59,137 @@ interface ITestData {
57
59
*/
58
60
cliVersion : string ;
59
61
62
+ /**
63
+ * Version, based on which the version of the package that will be installed is detected.
64
+ * Used when semantically the correct reference version is different than the CLI version.
65
+ * (e.g. inspector package version should be determined by the project's ios runtime version)
66
+ */
67
+ referenceVersion ?: string ;
68
+
60
69
/**
61
70
* Expected result
62
71
*/
63
72
expectedResult : string ;
64
73
}
65
74
66
75
describe ( "Npm installation manager tests" , ( ) => {
67
- const testData : IDictionary < ITestData > = {
68
- "when there's only one available version and it matches CLI's version" : {
69
- versions : [ "1.4.0" ] ,
70
- packageLatestVersion : "1.4.0" ,
71
- cliVersion : "1.4.0" ,
72
- expectedResult : "1.4.0"
73
- } ,
74
-
75
- "when there's only one available version and it is higher than match CLI's version" : {
76
- versions : [ "1.4.0" ] ,
77
- packageLatestVersion : "1.4.0" ,
78
- cliVersion : "1.2.0" ,
79
- expectedResult : "1.4.0"
80
- } ,
81
-
82
- "when there's only one available version and it is lower than CLI's version" : {
83
- versions : [ "1.4.0" ] ,
84
- packageLatestVersion : "1.4.0" ,
85
- cliVersion : "1.6.0" ,
86
- expectedResult : "1.4.0"
87
- } ,
88
-
89
- "when there are multiple package versions and the latest one matches ~<cli-version>" : {
90
- versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.3.2" , "1.3.3" , "1.4.0" ] ,
91
- packageLatestVersion : "1.3.3" ,
92
- cliVersion : "1.3.0" ,
93
- expectedResult : "1.3.3"
94
- } ,
95
-
96
- "when there are multiple package versions and the latest one matches ~<cli-version> when there are newer matching versions but they are not under latest tag" : {
97
- versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.3.2" , "1.3.3" , "1.4.0" ] ,
98
- packageLatestVersion : "1.3.2" ,
99
- cliVersion : "1.3.0" ,
100
- expectedResult : "1.3.2"
101
- } ,
102
-
103
- "when there are multiple package versions and the latest one is lower than ~<cli-version>" : {
104
- versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.3.2" , "1.3.3" , "1.4.0" ] ,
105
- packageLatestVersion : "1.4.0" ,
106
- cliVersion : "1.5.0" ,
107
- expectedResult : "1.4.0"
108
- } ,
109
-
110
- "when there are multiple package versions and there's beta version matching CLI's semver" : {
111
- versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.4.0" , "1.5.0-2016-02-25-182" ] ,
112
- packageLatestVersion : "1.4.0" ,
113
- cliVersion : "1.5.0" ,
114
- expectedResult : "1.4.0"
115
- } ,
116
-
117
- "when there are multiple package versions and package's latest version is greater than CLI's version" : {
118
- versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0" , "1.6.0" ] ,
119
- packageLatestVersion : "1.6.0" ,
120
- cliVersion : "1.5.0" ,
121
- expectedResult : "1.5.0"
122
- } ,
123
-
124
- "when there are multiple versions latest one does not match CLI's semver and other versions are not matching either" : {
125
- versions : [ "1.0.0" , "1.0.1" , "1.2.0" , "1.3.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0" ] ,
126
- packageLatestVersion : "1.0.0" ,
127
- cliVersion : "1.1.0" ,
128
- expectedResult : "1.0.0"
129
- } ,
130
-
131
- "when CLI's version is beta (has dash) latest matching beta version is returned" : {
132
- versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0-2016-02-26-202" ] ,
133
- packageLatestVersion : "1.4.0" ,
134
- cliVersion : "1.5.0-182" ,
135
- expectedResult : "1.5.0-2016-02-26-202"
136
- } ,
137
-
138
- "when CLI's version is beta (has dash) latest matching official version is returned when beta versions do not match" : {
139
- versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0-2016-02-26-202" ] ,
140
- packageLatestVersion : "1.4.0" ,
141
- cliVersion : "1.6.0-2016-03-01-182" ,
142
- expectedResult : "1.4.0"
143
- } ,
144
-
145
- "when CLI's version is beta (has dash) latest matching official version is returned when beta versions do not match (when the prerelease of CLI is higher than prerelease version of runtime)" : {
146
- versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "1.6.0-2016-02-25-182" , "1.6.0-2016-02-26-202" ] ,
147
- packageLatestVersion : "1.4.0" ,
148
- cliVersion : "1.6.0-2016-10-01-182" ,
149
- expectedResult : "1.4.0"
150
- } ,
151
- "When CLI Version has patch version larger than an existing package, should return max compliant package from the same major.minor version" : {
152
- versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "2.5.0" , "2.5.1" , "2.5.2" , "3.0.0" ] ,
153
- packageLatestVersion : "3.0.0" ,
154
- cliVersion : "2.5.4" ,
155
- expectedResult : "2.5.2"
156
- }
157
- } ;
76
+ describe ( "getLatestCompatibleVersion" , ( ) => {
77
+ const testData : IDictionary < ITestData > = {
78
+ "when there's only one available version and it matches CLI's version" : {
79
+ versions : [ "1.4.0" ] ,
80
+ packageLatestVersion : "1.4.0" ,
81
+ cliVersion : "1.4.0" ,
82
+ expectedResult : "1.4.0"
83
+ } ,
84
+
85
+ "when there's only one available version and it is higher than match CLI's version" : {
86
+ versions : [ "1.4.0" ] ,
87
+ packageLatestVersion : "1.4.0" ,
88
+ cliVersion : "1.2.0" ,
89
+ expectedResult : "1.4.0"
90
+ } ,
91
+
92
+ "when there's only one available version and it is lower than CLI's version" : {
93
+ versions : [ "1.4.0" ] ,
94
+ packageLatestVersion : "1.4.0" ,
95
+ cliVersion : "1.6.0" ,
96
+ expectedResult : "1.4.0"
97
+ } ,
98
+
99
+ "when there are multiple package versions and the latest one matches ~<cli-version>" : {
100
+ versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.3.2" , "1.3.3" , "1.4.0" ] ,
101
+ packageLatestVersion : "1.3.3" ,
102
+ cliVersion : "1.3.0" ,
103
+ expectedResult : "1.3.3"
104
+ } ,
105
+
106
+ "when there are multiple package versions and the latest one matches ~<cli-version> when there are newer matching versions but they are not under latest tag" : {
107
+ versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.3.2" , "1.3.3" , "1.4.0" ] ,
108
+ packageLatestVersion : "1.3.2" ,
109
+ cliVersion : "1.3.0" ,
110
+ expectedResult : "1.3.2"
111
+ } ,
112
+
113
+ "when there are multiple package versions and the latest one is lower than ~<cli-version>" : {
114
+ versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.3.2" , "1.3.3" , "1.4.0" ] ,
115
+ packageLatestVersion : "1.4.0" ,
116
+ cliVersion : "1.5.0" ,
117
+ expectedResult : "1.4.0"
118
+ } ,
119
+
120
+ "when there are multiple package versions and there's beta version matching CLI's semver" : {
121
+ versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.4.0" , "1.5.0-2016-02-25-182" ] ,
122
+ packageLatestVersion : "1.4.0" ,
123
+ cliVersion : "1.5.0" ,
124
+ expectedResult : "1.4.0"
125
+ } ,
126
+
127
+ "when there are multiple package versions and package's latest version is greater than CLI's version" : {
128
+ versions : [ "1.2.0" , "1.3.0" , "1.3.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0" , "1.6.0" ] ,
129
+ packageLatestVersion : "1.6.0" ,
130
+ cliVersion : "1.5.0" ,
131
+ expectedResult : "1.5.0"
132
+ } ,
133
+
134
+ "when there are multiple versions latest one does not match CLI's semver and other versions are not matching either" : {
135
+ versions : [ "1.0.0" , "1.0.1" , "1.2.0" , "1.3.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0" ] ,
136
+ packageLatestVersion : "1.0.0" ,
137
+ cliVersion : "1.1.0" ,
138
+ expectedResult : "1.0.0"
139
+ } ,
140
+
141
+ "when CLI's version is beta (has dash) latest matching beta version is returned" : {
142
+ versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0-2016-02-26-202" ] ,
143
+ packageLatestVersion : "1.4.0" ,
144
+ cliVersion : "1.5.0-182" ,
145
+ expectedResult : "1.5.0-2016-02-26-202"
146
+ } ,
147
+
148
+ "when CLI's version is beta (has dash) latest matching official version is returned when beta versions do not match" : {
149
+ versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "1.5.0-2016-02-25-182" , "1.5.0-2016-02-26-202" ] ,
150
+ packageLatestVersion : "1.4.0" ,
151
+ cliVersion : "1.6.0-2016-03-01-182" ,
152
+ expectedResult : "1.4.0"
153
+ } ,
154
+
155
+ "when CLI's version is beta (has dash) latest matching official version is returned when beta versions do not match (when the prerelease of CLI is higher than prerelease version of runtime)" : {
156
+ versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "1.6.0-2016-02-25-182" , "1.6.0-2016-02-26-202" ] ,
157
+ packageLatestVersion : "1.4.0" ,
158
+ cliVersion : "1.6.0-2016-10-01-182" ,
159
+ expectedResult : "1.4.0"
160
+ } ,
161
+ "When CLI Version has patch version larger than an existing package, should return max compliant package from the same major.minor version" : {
162
+ versions : [ "1.0.0" , "1.0.1" , "1.4.0" , "2.5.0" , "2.5.1" , "2.5.2" , "3.0.0" ] ,
163
+ packageLatestVersion : "3.0.0" ,
164
+ cliVersion : "2.5.4" ,
165
+ expectedResult : "2.5.2"
166
+ } ,
167
+ "When reference version is specified as argument" : {
168
+ versions : [ "122.0.4" , "123.0.0" , "123.0.1" , "123.1.0" , "124.0.0" ] ,
169
+ packageLatestVersion : "124.0.0" ,
170
+ cliVersion : "0.0.0" , // should not matter
171
+ expectedResult : "123.0.1" ,
172
+ referenceVersion : "123.0.5"
173
+ }
174
+ } ;
158
175
159
- _ . each ( testData , ( currentTestData : ITestData , testName : string ) => {
160
- it ( `returns correct latest compatible version, ${ testName } ` , async ( ) => {
161
- const testInjector = createTestInjector ( ) ;
176
+ _ . each ( testData , ( currentTestData : ITestData , testName : string ) => {
177
+ it ( `returns correct latest compatible version, ${ testName } ` , async ( ) => {
178
+ const testInjector = createTestInjector ( ) ;
162
179
163
- mockNpm ( testInjector , currentTestData . versions , currentTestData . packageLatestVersion ) ;
180
+ mockNpm ( testInjector , currentTestData . versions , currentTestData . packageLatestVersion ) ;
164
181
165
- // Mock staticConfig.version
166
- const staticConfig = testInjector . resolve ( "staticConfig" ) ;
167
- staticConfig . version = currentTestData . cliVersion ;
182
+ // Mock staticConfig.version
183
+ const staticConfig = testInjector . resolve ( "staticConfig" ) ;
184
+ staticConfig . version = currentTestData . cliVersion ;
168
185
169
- // Mock npmInstallationManager.getLatestVersion
170
- const npmInstallationManager = testInjector . resolve ( "npmInstallationManager" ) ;
171
- npmInstallationManager . getLatestVersion = ( packageName : string ) => Promise . resolve ( currentTestData . packageLatestVersion ) ;
186
+ // Mock npmInstallationManager.getLatestVersion
187
+ const npmInstallationManager = testInjector . resolve ( "npmInstallationManager" ) ;
188
+ npmInstallationManager . getLatestVersion = ( packageName : string ) => Promise . resolve ( currentTestData . packageLatestVersion ) ;
172
189
173
- const actualLatestCompatibleVersion = await npmInstallationManager . getLatestCompatibleVersion ( "" ) ;
174
- assert . equal ( actualLatestCompatibleVersion , currentTestData . expectedResult ) ;
190
+ const actualLatestCompatibleVersion = await npmInstallationManager . getLatestCompatibleVersion ( "" , currentTestData . referenceVersion ) ;
191
+ assert . equal ( actualLatestCompatibleVersion , currentTestData . expectedResult ) ;
192
+ } ) ;
175
193
} ) ;
176
194
} ) ;
177
195
} ) ;
0 commit comments