Skip to content

Commit a8a74c4

Browse files
authored
testProvider: fix continuous run handling (microsoft#917)
Fixes microsoft#900
1 parent ff51306 commit a8a74c4

2 files changed

Lines changed: 35 additions & 80 deletions

File tree

‎test-provider-sample/src/extension.ts‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
import * as vscode from 'vscode';
2-
import { getContentFromFilesystem, MarkdownTestData, TestCase, testData, TestFile } from './testTree';
2+
import { getContentFromFilesystem, TestCase, testData, TestFile } from './testTree';
33

44
export async function activate(context: vscode.ExtensionContext) {
55
const ctrl = vscode.tests.createTestController('mathTestController', 'Markdown Math');
66
context.subscriptions.push(ctrl);
77

88
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) => {
1032
if (!request.continuous) {
1133
return startTestRun(request);
1234
}
1335

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+
}
2343
};
2444

2545
const startTestRun = (request: vscode.TestRunRequest) => {
@@ -74,8 +94,9 @@ export async function activate(context: vscode.ExtensionContext) {
7494

7595
const lineNo = test.range!.start.line;
7696
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++;
79100
}
80101

81102
run.appendOutput(`Completed ${test.id}\r\n`);
@@ -183,7 +204,7 @@ async function findInitialFiles(controller: vscode.TestController, pattern: vsco
183204
}
184205
}
185206

186-
function startWatchingWorkspace(controller: vscode.TestController, fileChangedEmitter: vscode.EventEmitter<vscode.Uri> ) {
207+
function startWatchingWorkspace(controller: vscode.TestController, fileChangedEmitter: vscode.EventEmitter<vscode.Uri>) {
187208
return getWorkspaceTestPatterns().map(({ workspaceFolder, pattern }) => {
188209
const watcher = vscode.workspace.createFileSystemWatcher(pattern);
189210

‎test-provider-sample/vscode.proposed.testContinuousRun.d.ts‎

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)