@@ -3,6 +3,7 @@ package project_test
3
3
import (
4
4
"slices"
5
5
"testing"
6
+ "time"
6
7
7
8
"github.com/microsoft/typescript-go/internal/bundled"
8
9
"github.com/microsoft/typescript-go/internal/core"
@@ -215,16 +216,12 @@ func TestAta(t *testing.T) {
215
216
_ , p2 := service .EnsureDefaultProjectForFile ("/user/username/projects/project2/app.js" )
216
217
var installStatuses []project.TypingsInstallerStatus
217
218
installStatuses = append (installStatuses , <- host .ServiceOptions .InstallStatus , <- host .ServiceOptions .InstallStatus )
218
- // Order can be non deterministic since they both will run in parallel
219
- assert .Assert (t , slices .Contains (installStatuses , project.TypingsInstallerStatus {
220
- RequestId : 1 ,
221
- Project : p1 ,
222
- Status : "Success" ,
219
+ // Order can be non deterministic since they both will run in parallel - not looking into request ID
220
+ assert .Assert (t , slices .ContainsFunc (installStatuses , func (s project.TypingsInstallerStatus ) bool {
221
+ return s .Project == p1 && s .Status == "Success"
223
222
}))
224
- assert .Assert (t , slices .Contains (installStatuses , project.TypingsInstallerStatus {
225
- RequestId : 2 ,
226
- Project : p2 ,
227
- Status : "Success" ,
223
+ assert .Assert (t , slices .ContainsFunc (installStatuses , func (s project.TypingsInstallerStatus ) bool {
224
+ return s .Project == p2 && s .Status == "Success"
228
225
}))
229
226
})
230
227
@@ -242,6 +239,7 @@ func TestAta(t *testing.T) {
242
239
"typeAcquisition": { "include": ["grunt", "gulp", "commander"] },
243
240
}` ,
244
241
}
242
+ expectedP1First := true
245
243
service , host := projecttestutil .Setup (files , & projecttestutil.TestTypingsInstaller {
246
244
TestTypingsInstallerOptions : projecttestutil.TestTypingsInstallerOptions {
247
245
PackageToFile : map [string ]string {
@@ -250,31 +248,40 @@ func TestAta(t *testing.T) {
250
248
"lodash" : "declare const lodash: { x: number }" ,
251
249
"cordova" : "declare const cordova: { x: number }" ,
252
250
"grunt" : "declare const grunt: { x: number }" ,
253
- "gulp" : "declare const grunt : { x: number }" ,
251
+ "gulp" : "declare const gulp : { x: number }" ,
254
252
},
255
253
},
256
254
TypingsInstallerOptions : project.TypingsInstallerOptions {
257
255
ThrottleLimit : 1 ,
258
256
},
259
257
})
260
258
259
+ host .TestOptions .CheckBeforeNpmInstall = func (cwd string , npmInstallArgs []string ) {
260
+ for {
261
+ pendingCount := service .TypingsInstaller ().PendingRunRequestsCount ()
262
+ if pendingCount == 1 {
263
+ if slices .Contains (npmInstallArgs , "@types/gulp@latest" ) {
264
+ expectedP1First = false
265
+ }
266
+ host .TestOptions .CheckBeforeNpmInstall = nil // Stop checking after first run
267
+ break
268
+ }
269
+ assert .NilError (t , t .Context ().Err ())
270
+ time .Sleep (10 * time .Millisecond )
271
+ }
272
+ }
273
+
261
274
service .OpenFile ("/user/username/projects/project1/app.js" , files ["/user/username/projects/project1/app.js" ].(string ), core .ScriptKindJS , "" )
262
275
service .OpenFile ("/user/username/projects/project2/app.js" , files ["/user/username/projects/project2/app.js" ].(string ), core .ScriptKindJS , "" )
263
276
_ , p1 := service .EnsureDefaultProjectForFile ("/user/username/projects/project1/app.js" )
264
277
_ , p2 := service .EnsureDefaultProjectForFile ("/user/username/projects/project2/app.js" )
265
278
// Order is determinate since second install will run only after completing first one
266
279
status := <- host .ServiceOptions .InstallStatus
267
- assert .Equal (t , status , project.TypingsInstallerStatus {
268
- RequestId : 1 ,
269
- Project : p1 ,
270
- Status : "Success" ,
271
- })
280
+ assert .Equal (t , status .Project , core .IfElse (expectedP1First , p1 , p2 ))
281
+ assert .Equal (t , status .Status , "Success" )
272
282
status = <- host .ServiceOptions .InstallStatus
273
- assert .Equal (t , status , project.TypingsInstallerStatus {
274
- RequestId : 2 ,
275
- Project : p2 ,
276
- Status : "Success" ,
277
- })
283
+ assert .Equal (t , status .Project , core .IfElse (expectedP1First , p2 , p1 ))
284
+ assert .Equal (t , status .Status , "Success" )
278
285
})
279
286
280
287
t .Run ("discover from node_modules" , func (t * testing.T ) {
0 commit comments