|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +import * as assert from 'assert'; |
| 4 | +import * as Path from 'path'; |
| 5 | +import * as vscode from 'vscode'; |
| 6 | + |
| 7 | +suite('Extension Smoke', () => { |
| 8 | + test('activates and publishes diagnostics for Java files', async () => { |
| 9 | + const extension = vscode.extensions.getExtension('georgewfraser.vscode-javac'); |
| 10 | + assert.ok(extension, 'Extension georgewfraser.vscode-javac was not found'); |
| 11 | + |
| 12 | + await extension.activate(); |
| 13 | + |
| 14 | + const commands = await vscode.commands.getCommands(true); |
| 15 | + assert.ok(commands.includes('java.command.findReferences'), 'Expected Java commands to be registered'); |
| 16 | + |
| 17 | + const folders = vscode.workspace.workspaceFolders; |
| 18 | + assert.ok(folders && folders.length > 0, 'Expected the smoke-test workspace to be open'); |
| 19 | + |
| 20 | + const uri = vscode.Uri.file(Path.join(folders[0].uri.fsPath, 'HelloError.java')); |
| 21 | + const document = await vscode.workspace.openTextDocument(uri); |
| 22 | + await vscode.window.showTextDocument(document); |
| 23 | + |
| 24 | + const diagnostics = await waitForDiagnostics(uri, 90000); |
| 25 | + const messages = diagnostics.map(d => d.message).join(' | '); |
| 26 | + |
| 27 | + assert.ok( |
| 28 | + diagnostics.some(d => d.severity === vscode.DiagnosticSeverity.Error), |
| 29 | + `Expected an error diagnostic for HelloError.java, got: ${messages || '<none>'}` |
| 30 | + ); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +async function waitForDiagnostics(uri: vscode.Uri, timeoutMs: number): Promise<vscode.Diagnostic[]> { |
| 35 | + const start = Date.now(); |
| 36 | + |
| 37 | + while (Date.now() - start < timeoutMs) { |
| 38 | + const diagnostics = vscode.languages.getDiagnostics(uri); |
| 39 | + if (diagnostics.some(d => d.severity === vscode.DiagnosticSeverity.Error)) { |
| 40 | + return diagnostics; |
| 41 | + } |
| 42 | + await delay(250); |
| 43 | + } |
| 44 | + |
| 45 | + return vscode.languages.getDiagnostics(uri); |
| 46 | +} |
| 47 | + |
| 48 | +function delay(ms: number): Promise<void> { |
| 49 | + return new Promise(resolve => setTimeout(resolve, ms)); |
| 50 | +} |
0 commit comments