Skip to content

Commit 74b7c5f

Browse files
committed
Remove test ws in runTest instead in test suite
Printing out the contents always and remove only if tests were succesfull
1 parent 3c435af commit 74b7c5f

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

test/runTest.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// tslint:disable: no-console
12
import * as cp from 'child_process';
23
import * as fs from 'fs';
34
import * as path from 'path';
@@ -12,9 +13,20 @@ function installExtension(vscodeExePath: string, extId: string) {
1213
});
1314
}
1415

16+
function showDirContens(dir: string) {
17+
console.log(dir);
18+
const files = fs.readdirSync(dir, { withFileTypes: true });
19+
files.forEach((file: fs.Dirent) => {
20+
const absPath = path.resolve(dir, file.name);
21+
if (file.isDirectory()) {
22+
showDirContens(absPath);
23+
}
24+
});
25+
}
26+
1527
async function main() {
1628
try {
17-
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.61.2');
29+
const vscodeExecutablePath = await downloadAndUnzipVSCode('stable');
1830

1931
// We have to install this dependant extension
2032
installExtension(vscodeExecutablePath, 'justusadam.language-haskell');
@@ -34,12 +46,19 @@ async function main() {
3446
}
3547

3648
// Download VS Code, unzip it and run the integration test
37-
await runTests({
49+
const exitCode = await runTests({
3850
vscodeExecutablePath,
3951
extensionDevelopmentPath,
4052
extensionTestsPath,
4153
launchArgs: [testWorkspace],
4254
});
55+
56+
console.log('Test workspace contents: ');
57+
showDirContens(testWorkspace);
58+
if (exitCode === 0) {
59+
console.log(`Tests were succesfull, deleting test workspace in ${testWorkspace}`)
60+
fs.rmdirSync(testWorkspace, { recursive: true });
61+
}
4362
} catch (err) {
4463
console.error(err);
4564
console.error('Failed to run tests');

test/suite/extension.test.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ function getWorkspaceFile(name: string) {
3131
return wsroot.with({ path: path.posix.join(wsroot.path, name) });
3232
}
3333

34-
async function deleteWorkspaceFiles() {
35-
const dirContents = await vscode.workspace.fs.readDirectory(getWorkspaceRoot().uri);
36-
console.log(`Deleting test ws contents: ${dirContents}`);
37-
dirContents.forEach(async ([name, type]) => {
38-
const uri: vscode.Uri = getWorkspaceFile(name);
39-
console.log(`Deleting ${uri}`);
40-
await vscode.workspace.fs.delete(getWorkspaceFile(name), { recursive: true });
41-
});
42-
}
43-
4434
suite('Extension Test Suite', () => {
4535
const disposables: vscode.Disposable[] = [];
4636

@@ -61,11 +51,11 @@ suite('Extension Test Suite', () => {
6151
vscode.window.showInformationMessage('Start all tests.');
6252

6353
suiteSetup(async () => {
64-
await deleteWorkspaceFiles();
6554
await getHaskellConfig().update('logFile', 'hls.log');
6655
await getHaskellConfig().update('trace.server', 'messages');
6756
await getHaskellConfig().update('releasesDownloadStoragePath', path.normalize(getWorkspaceFile('bin').fsPath));
68-
await getHaskellConfig().update('serverEnvironment', { XDG_CACHE_HOME: path.normalize(getWorkspaceFile('cache-test').fsPath) });
57+
await getHaskellConfig().update('serverEnvironment',
58+
{ XDG_CACHE_HOME: path.normalize(getWorkspaceFile('cache-test').fsPath) });
6959
const contents = new TextEncoder().encode('main = putStrLn "hi vscode tests"');
7060
await vscode.workspace.fs.writeFile(getWorkspaceFile('Main.hs'), contents);
7161
});
@@ -110,9 +100,9 @@ suite('Extension Test Suite', () => {
110100
});
111101

112102
suiteTeardown(async () => {
103+
console.log('Disposing all resources')
113104
disposables.forEach((d) => d.dispose());
105+
console.log('Stopping the lsp server');
114106
await vscode.commands.executeCommand(CommandNames.StopServerCommandName);
115-
delay(5); // to give time to shutdown server
116-
await deleteWorkspaceFiles();
117107
});
118108
});

0 commit comments

Comments
 (0)