@@ -15,6 +15,8 @@ const validSubDirGlobalJson = workingSubDir + "global.json";
15
15
const subDirVersionNumber = "3.0.0-pre285754637" ;
16
16
const pathToEmptyGlobalJsonDir = workingDir + "empty/" ;
17
17
const pathToEmptyGlobalJson = pathToEmptyGlobalJsonDir + "global.json" ;
18
+ const pathToGlobalJsonWithCommentsDir = workingDir + "comments/" ;
19
+ const pathToGlobalJsonWithComments = pathToGlobalJsonWithCommentsDir + "global.json" ;
18
20
19
21
//setup mocks
20
22
mockery . enable ( {
@@ -38,6 +40,9 @@ mockery.registerMock('azure-pipelines-task-lib/task', {
38
40
if ( path == pathToEmptyGlobalJsonDir ) {
39
41
return [ pathToEmptyGlobalJson ] ;
40
42
}
43
+ if ( path == pathToGlobalJsonWithCommentsDir ) {
44
+ return [ pathToGlobalJsonWithComments ] ;
45
+ }
41
46
return [ ] ;
42
47
} ,
43
48
loc : function ( locString , ...param : string [ ] ) { return tl . loc ( locString , param ) ; } ,
@@ -58,6 +63,17 @@ mockery.registerMock('fs', {
58
63
if ( path == pathToEmptyGlobalJson ) {
59
64
return Buffer . from ( "" ) ;
60
65
}
66
+ if ( path == pathToGlobalJsonWithComments ) {
67
+ return Buffer . from ( `{
68
+ /*
69
+ This is a mult-line comment
70
+ */
71
+ "sdk": {
72
+ // This is a single-line comment
73
+ "version": "${ rootVersionNumber } "
74
+ }
75
+ }` ) ;
76
+ }
61
77
return Buffer . from ( null ) ;
62
78
}
63
79
} ) ;
@@ -133,4 +149,18 @@ if (process.env["__case__"] == "emptyGlobalJson") {
133
149
} , err => {
134
150
throw "GetVersions shouldn't throw an error if global.json is empty." ;
135
151
} ) ;
152
+ }
153
+
154
+ if ( process . env [ "__case__" ] == "globalJsonWithComments" ) {
155
+ let fetcher = new globalJsonFetcher ( pathToGlobalJsonWithCommentsDir ) ;
156
+ fetcher . GetVersions ( ) . then ( versionInfos => {
157
+ if ( versionInfos == null ) {
158
+ throw "GetVersions shouldn't return null if the global.json has comments." ;
159
+ }
160
+ if ( versionInfos . length != 1 ) {
161
+ throw "GetVersions shouldn't return a arry with 0 elements if global.json has comments." ;
162
+ }
163
+ } , err => {
164
+ throw "GetVersions shouldn't throw an error if global.json has comments." ;
165
+ } ) ;
136
166
}
0 commit comments