Skip to content

Commit 779f211

Browse files
committed
Set file watchers at test start
1 parent ef422c4 commit 779f211

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

test/suite/extension.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function getWorkspaceFile(name: string) {
3333

3434
suite('Extension Test Suite', () => {
3535
const disposables: vscode.Disposable[] = [];
36+
const filesCreated: Map<string, Promise<vscode.Uri>> = new Map();
3637

3738
async function existsWorkspaceFile(pattern: string, pred?: (uri: vscode.Uri) => boolean) {
3839
const relPath: vscode.RelativePattern = new vscode.RelativePattern(getWorkspaceRoot(), pattern);
@@ -58,6 +59,13 @@ suite('Extension Test Suite', () => {
5859
{ XDG_CACHE_HOME: path.normalize(getWorkspaceFile('cache-test').fsPath) });
5960
const contents = new TextEncoder().encode('main = putStrLn "hi vscode tests"');
6061
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'));
6169
});
6270

6371
test('Extension should be present', () => {
@@ -71,30 +79,28 @@ suite('Extension Test Suite', () => {
7179

7280
test('HLS executables should be downloaded', async () => {
7381
await vscode.workspace.openTextDocument(getWorkspaceFile('Main.hs'));
74-
const exeExt = os.platform.toString() === 'win32' ? '.exe' : '';
7582
console.log('Testing wrapper');
76-
const pred = (uri: vscode.Uri) => !['download', 'gz', 'zip'].includes(path.extname(uri.fsPath));
7783
assert.ok(
78-
await withTimeout(30, existsWorkspaceFile(`bin/haskell-language-server-wrapper*${exeExt}`, pred)),
84+
await withTimeout(30, filesCreated.get('wrapper')!),
7985
'The wrapper executable was not downloaded in 30 seconds'
8086
);
8187
console.log('Testing server');
8288
assert.ok(
83-
await withTimeout(60, existsWorkspaceFile(`bin/haskell-language-server-[1-9]*${exeExt}`, pred)),
89+
await withTimeout(60, filesCreated.get('server')!),
8490
'The server executable was not downloaded in 60 seconds'
8591
);
8692
});
8793

8894
test('Server log should be created', async () => {
8995
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');
9197
});
9298

9399
test('Server should inherit environment variables defined in the settings', async () => {
94100
await vscode.workspace.openTextDocument(getWorkspaceFile('Main.hs'));
95101
assert.ok(
96102
// 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')!),
98104
'Server did not inherit XDG_CACHE_DIR from environment variables set in the settings'
99105
);
100106
});

0 commit comments

Comments
 (0)