|
1 | | -import * as assert from 'assert'; |
2 | | -import { join } from 'path'; |
3 | | -import { commands, extensions, languages, StatusBarItem, Uri, window, workspace } from 'vscode'; |
4 | | - |
5 | | -suite('code-coverage', () => { |
6 | | - const exampleWorkspace = join(__dirname, '../../../', 'example'); |
7 | | - const exampleWorkspaceUri = Uri.file(exampleWorkspace); |
8 | | - const exampleIndexFile = join(exampleWorkspace, 'index.ts'); |
9 | | - const extension = extensions.getExtension("markis.code-coverage"); |
10 | | - |
11 | | - setup(async () => { |
12 | | - // Open the example workspace and open the example index file |
13 | | - await commands.executeCommand('vscode.openFolder', exampleWorkspaceUri); |
14 | | - const doc = await workspace.openTextDocument(exampleIndexFile); |
15 | | - await window.showTextDocument(doc); |
16 | | - }); |
17 | | - |
18 | | - teardown(async () => { |
19 | | - // All done, close the editor |
20 | | - commands.executeCommand('workbench.action.closeActiveEditor'); |
21 | | - }); |
22 | | - |
23 | | - test('check diagnostics exist', async () => { |
24 | | - // Check to see if the diagnostics exist for the example file |
25 | | - // there should only be one line not covered, and so only one diagnostic should exist |
26 | | - const diagnostics = languages.getDiagnostics(Uri.file(exampleIndexFile)); |
27 | | - assert.strictEqual(diagnostics.length, 1); |
28 | | - assert.strictEqual(diagnostics[0].range.start.line, 5); |
29 | | - }); |
30 | | - |
31 | | - test('check status bar', async () => { |
32 | | - // Check to see if the status bar is updated correctly |
33 | | - // the example coverage should cover 3 out of 4 lines - "3/4" |
34 | | - const statusBar: StatusBarItem = extension?.exports.statusBar; |
35 | | - assert.ok(statusBar.text); |
36 | | - assert.ok(statusBar.text.includes('3/4')) |
37 | | - }); |
38 | | -}); |
| 1 | +import * as assert from "assert"; |
| 2 | +import { join } from "path"; |
| 3 | +import { |
| 4 | + commands, |
| 5 | + extensions, |
| 6 | + languages, |
| 7 | + StatusBarItem, |
| 8 | + Uri, |
| 9 | + window, |
| 10 | + workspace, |
| 11 | + Extension, |
| 12 | +} from "vscode"; |
| 13 | + |
| 14 | +suite("code-coverage", function () { |
| 15 | + this.timeout(10000); |
| 16 | + const exampleWorkspace = join(__dirname, "../../../", "example"); |
| 17 | + const exampleWorkspaceUri = Uri.file(exampleWorkspace); |
| 18 | + const exampleIndexUri = Uri.file(join(exampleWorkspace, "index.ts")); |
| 19 | + let extension: Extension<any> | undefined; |
| 20 | + let onCommand: (cmd: string) => Promise<void> | undefined; |
| 21 | + |
| 22 | + setup(async () => { |
| 23 | + // Open the example workspace and open the example index file |
| 24 | + await commands.executeCommand("vscode.openFolder", exampleWorkspaceUri); |
| 25 | + const doc = await workspace.openTextDocument(exampleIndexUri); |
| 26 | + await window.showTextDocument(doc); |
| 27 | + extension = extensions.getExtension("markis.code-coverage"); |
| 28 | + onCommand = extension?.exports.onCommand; |
| 29 | + }); |
| 30 | + |
| 31 | + teardown(async () => { |
| 32 | + // All done, close the editor |
| 33 | + commands.executeCommand("workbench.action.closeActiveEditor"); |
| 34 | + }); |
| 35 | + |
| 36 | + test("check diagnostics exist", async () => { |
| 37 | + // Check to see if the diagnostics exist for the example file |
| 38 | + // there should only be one line not covered, and so only one diagnostic should exist |
| 39 | + const diagnostics = languages.getDiagnostics(exampleIndexUri); |
| 40 | + assert.strictEqual(diagnostics.length, 1); |
| 41 | + assert.strictEqual(diagnostics[0].range.start.line, 5); |
| 42 | + }); |
| 43 | + |
| 44 | + test("check status bar", async () => { |
| 45 | + // Check to see if the status bar is updated correctly |
| 46 | + // the example coverage should cover 3 out of 4 lines - "3/4" |
| 47 | + const statusBar: StatusBarItem = extension?.exports.statusBar; |
| 48 | + assert.ok(statusBar.text); |
| 49 | + assert.ok(statusBar.text.includes("3/4")); |
| 50 | + }); |
| 51 | + |
| 52 | + test("test commands hide coverage", async () => { |
| 53 | + // Ensure coverage exists |
| 54 | + assert.strictEqual(languages.getDiagnostics(exampleIndexUri).length, 1); |
| 55 | + |
| 56 | + // Hide coverage |
| 57 | + await onCommand("code-coverage.hide"); |
| 58 | + assert.strictEqual(languages.getDiagnostics(exampleIndexUri).length, 0); |
| 59 | + }); |
| 60 | + |
| 61 | + test("test commands show coverage", async () => { |
| 62 | + // Show coverage |
| 63 | + await onCommand("code-coverage.show"); |
| 64 | + assert.strictEqual(languages.getDiagnostics(exampleIndexUri).length, 1); |
| 65 | + }); |
| 66 | +}); |
0 commit comments