testing: run all tests with equivalent range at cursor

Fixes #133519
This commit is contained in:
Connor Peet
2021-10-08 12:18:20 -07:00
parent 30e17436c5
commit 649a1afa53
2 changed files with 20 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { Iterable } from 'vs/base/common/iterator';
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { isDefined } from 'vs/base/common/types';
import { Range } from 'vs/editor/common/core/range';
import { IRange, Range } from 'vs/editor/common/core/range';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { localize } from 'vs/nls';
import { Action2, IAction2Options, MenuId } from 'vs/platform/actions/common/actions';
@@ -730,21 +730,34 @@ abstract class ExecuteTestAtCursor extends Action2 {
}
const testService = accessor.get(ITestService);
let bestNode: InternalTestItem | undefined;
const profileService = accessor.get(ITestProfileService);
let bestNodes: InternalTestItem[] = [];
let bestRange: IRange | undefined;
// testsInFile will descend in the test tree. We assume that as we go
// deeper, ranges get more specific. We'll want to run all tests whose
// range is equal to the most specific range we find (see #133519)
await showDiscoveringWhile(accessor.get(IProgressService), (async () => {
for await (const test of testsInFile(testService.collection, model.uri)) {
if (test.item.range && Range.containsPosition(test.item.range, position)) {
bestNode = test;
if (!test.item.range || !Range.containsPosition(test.item.range, position) || !(profileService.capabilitiesForTest(test) & this.group)) {
continue;
}
if (bestRange && Range.equalsRange(test.item.range, bestRange)) {
bestNodes.push(test);
} else {
bestRange = test.item.range;
bestNodes = [test];
}
}
})());
if (bestNode) {
if (bestNodes.length) {
await testService.runTests({
group: this.group,
tests: [bestNode],
tests: bestNodes,
});
}
}

View File

@@ -48,7 +48,6 @@ import { ITestProfileService } from 'vs/workbench/contrib/testing/common/testPro
import { LiveTestResult } from 'vs/workbench/contrib/testing/common/testResult';
import { ITestResultService } from 'vs/workbench/contrib/testing/common/testResultService';
import { getContextForTestItem, ITestService, testsInFile } from 'vs/workbench/contrib/testing/common/testService';
import { ITextEditorService } from 'vs/workbench/services/textfile/common/textEditorService';
function isOriginalInDiffEditor(codeEditorService: ICodeEditorService, codeEditor: ICodeEditor): boolean {
const diffEditors = codeEditorService.listDiffEditors();
@@ -563,7 +562,7 @@ abstract class RunTestDecoration {
}[],
private visible: boolean,
protected readonly model: ITextModel,
@ITextEditorService private readonly codeEditorService: ICodeEditorService,
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
@ITestService protected readonly testService: ITestService,
@IContextMenuService protected readonly contextMenuService: IContextMenuService,
@ICommandService protected readonly commandService: ICommandService,