|
1 | 1 | import * as vscode from 'vscode'; |
2 | | -import { getContentFromFilesystem, MarkdownTestData, TestCase, testData, TestFile } from './testTree'; |
| 2 | +import { getContentFromFilesystem, TestCase, testData, TestFile } from './testTree'; |
3 | 3 |
|
4 | 4 | export async function activate(context: vscode.ExtensionContext) { |
5 | 5 | const ctrl = vscode.tests.createTestController('mathTestController', 'Markdown Math'); |
6 | 6 | context.subscriptions.push(ctrl); |
7 | 7 |
|
8 | 8 | const fileChangedEmitter = new vscode.EventEmitter<vscode.Uri>(); |
9 | | - const runHandler = (request: vscode.TestRunRequest2, cancellation: vscode.CancellationToken) => { |
| 9 | + const watchingTests = new Map<vscode.TestItem | 'ALL', vscode.TestRunProfile | undefined>(); |
| 10 | + fileChangedEmitter.event(uri => { |
| 11 | + if (watchingTests.has('ALL')) { |
| 12 | + startTestRun(new vscode.TestRunRequest(undefined, undefined, watchingTests.get('ALL'), true)); |
| 13 | + return; |
| 14 | + } |
| 15 | + |
| 16 | + const include: vscode.TestItem[] = []; |
| 17 | + let profile: vscode.TestRunProfile | undefined; |
| 18 | + for (const [item, thisProfile] of watchingTests) { |
| 19 | + const cast = item as vscode.TestItem; |
| 20 | + if (cast.uri?.toString() == uri.toString()) { |
| 21 | + include.push(cast); |
| 22 | + profile = thisProfile; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + if (include.length) { |
| 27 | + startTestRun(new vscode.TestRunRequest(include, undefined, profile, true)); |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + const runHandler = (request: vscode.TestRunRequest, cancellation: vscode.CancellationToken) => { |
10 | 32 | if (!request.continuous) { |
11 | 33 | return startTestRun(request); |
12 | 34 | } |
13 | 35 |
|
14 | | - const l = fileChangedEmitter.event(uri => startTestRun( |
15 | | - new vscode.TestRunRequest2( |
16 | | - [getOrCreateFile(ctrl, uri).file], |
17 | | - undefined, |
18 | | - request.profile, |
19 | | - true |
20 | | - ), |
21 | | - )); |
22 | | - cancellation.onCancellationRequested(() => l.dispose()); |
| 36 | + if (request.include === undefined) { |
| 37 | + watchingTests.set('ALL', request.profile); |
| 38 | + cancellation.onCancellationRequested(() => watchingTests.delete('ALL')); |
| 39 | + } else { |
| 40 | + request.include.forEach(item => watchingTests.set(item, request.profile)); |
| 41 | + cancellation.onCancellationRequested(() => request.include!.forEach(item => watchingTests.delete(item))); |
| 42 | + } |
23 | 43 | }; |
24 | 44 |
|
25 | 45 | const startTestRun = (request: vscode.TestRunRequest) => { |
@@ -74,8 +94,9 @@ export async function activate(context: vscode.ExtensionContext) { |
74 | 94 |
|
75 | 95 | const lineNo = test.range!.start.line; |
76 | 96 | const fileCoverage = coveredLines.get(test.uri!.toString()); |
77 | | - if (fileCoverage) { |
78 | | - fileCoverage[lineNo]!.executionCount++; |
| 97 | + const lineInfo = fileCoverage?.[lineNo]; |
| 98 | + if (lineInfo) { |
| 99 | + lineInfo.executionCount++; |
79 | 100 | } |
80 | 101 |
|
81 | 102 | run.appendOutput(`Completed ${test.id}\r\n`); |
@@ -183,7 +204,7 @@ async function findInitialFiles(controller: vscode.TestController, pattern: vsco |
183 | 204 | } |
184 | 205 | } |
185 | 206 |
|
186 | | -function startWatchingWorkspace(controller: vscode.TestController, fileChangedEmitter: vscode.EventEmitter<vscode.Uri> ) { |
| 207 | +function startWatchingWorkspace(controller: vscode.TestController, fileChangedEmitter: vscode.EventEmitter<vscode.Uri>) { |
187 | 208 | return getWorkspaceTestPatterns().map(({ workspaceFolder, pattern }) => { |
188 | 209 | const watcher = vscode.workspace.createFileSystemWatcher(pattern); |
189 | 210 |
|
|
0 commit comments