@@ -33,6 +33,7 @@ function getWorkspaceFile(name: string) {
33
33
34
34
suite ( 'Extension Test Suite' , ( ) => {
35
35
const disposables : vscode . Disposable [ ] = [ ] ;
36
+ const filesCreated : Map < string , Promise < vscode . Uri > > = new Map ( ) ;
36
37
37
38
async function existsWorkspaceFile ( pattern : string , pred ?: ( uri : vscode . Uri ) => boolean ) {
38
39
const relPath : vscode . RelativePattern = new vscode . RelativePattern ( getWorkspaceRoot ( ) , pattern ) ;
@@ -58,6 +59,13 @@ suite('Extension Test Suite', () => {
58
59
{ XDG_CACHE_HOME : path . normalize ( getWorkspaceFile ( 'cache-test' ) . fsPath ) } ) ;
59
60
const contents = new TextEncoder ( ) . encode ( 'main = putStrLn "hi vscode tests"' ) ;
60
61
await vscode . workspace . fs . writeFile ( getWorkspaceFile ( 'Main.hs' ) , contents ) ;
62
+
63
+ const pred = ( uri : vscode . Uri ) => ! [ 'download' , 'gz' , 'zip' ] . includes ( path . extname ( uri . fsPath ) ) ;
64
+ const exeExt = os . platform . toString ( ) === 'win32' ? '.exe' : '' ;
65
+ filesCreated . set ( 'wrapper' , existsWorkspaceFile ( `bin/haskell-language-server-wrapper*${ exeExt } ` , pred ) ) ;
66
+ filesCreated . set ( 'server' , existsWorkspaceFile ( `bin/haskell-language-server-[1-9]*${ exeExt } ` , pred ) ) ;
67
+ filesCreated . set ( 'log' , existsWorkspaceFile ( 'hls.log' ) ) ;
68
+ filesCreated . set ( 'cache' , existsWorkspaceFile ( 'cache-test' ) ) ;
61
69
} ) ;
62
70
63
71
test ( 'Extension should be present' , ( ) => {
@@ -71,30 +79,28 @@ suite('Extension Test Suite', () => {
71
79
72
80
test ( 'HLS executables should be downloaded' , async ( ) => {
73
81
await vscode . workspace . openTextDocument ( getWorkspaceFile ( 'Main.hs' ) ) ;
74
- const exeExt = os . platform . toString ( ) === 'win32' ? '.exe' : '' ;
75
82
console . log ( 'Testing wrapper' ) ;
76
- const pred = ( uri : vscode . Uri ) => ! [ 'download' , 'gz' , 'zip' ] . includes ( path . extname ( uri . fsPath ) ) ;
77
83
assert . ok (
78
- await withTimeout ( 30 , existsWorkspaceFile ( `bin/haskell-language-server- wrapper* ${ exeExt } ` , pred ) ) ,
84
+ await withTimeout ( 30 , filesCreated . get ( ' wrapper' ) ! ) ,
79
85
'The wrapper executable was not downloaded in 30 seconds'
80
86
) ;
81
87
console . log ( 'Testing server' ) ;
82
88
assert . ok (
83
- await withTimeout ( 60 , existsWorkspaceFile ( `bin/haskell-language- server-[1-9]* ${ exeExt } ` , pred ) ) ,
89
+ await withTimeout ( 60 , filesCreated . get ( ' server' ) ! ) ,
84
90
'The server executable was not downloaded in 60 seconds'
85
91
) ;
86
92
} ) ;
87
93
88
94
test ( 'Server log should be created' , async ( ) => {
89
95
await vscode . workspace . openTextDocument ( getWorkspaceFile ( 'Main.hs' ) ) ;
90
- assert . ok ( await withTimeout ( 30 , existsWorkspaceFile ( 'hls. log') ) , 'Server log not created in 30 seconds' ) ;
96
+ assert . ok ( await withTimeout ( 30 , filesCreated . get ( ' log') ! ) , 'Server log not created in 30 seconds' ) ;
91
97
} ) ;
92
98
93
99
test ( 'Server should inherit environment variables defined in the settings' , async ( ) => {
94
100
await vscode . workspace . openTextDocument ( getWorkspaceFile ( 'Main.hs' ) ) ;
95
101
assert . ok (
96
102
// Folder will have already been created by this point, so it will not trigger watcher in existsWorkspaceFile()
97
- vscode . workspace . getWorkspaceFolder ( getWorkspaceFile ( 'cache-test' ) ) ,
103
+ await withTimeout ( 30 , filesCreated . get ( 'cache' ) ! ) ,
98
104
'Server did not inherit XDG_CACHE_DIR from environment variables set in the settings'
99
105
) ;
100
106
} ) ;
0 commit comments