Skip to content

Commit cb073da

Browse files
committed
Command for triggering running tests in parallel
1 parent dfed159 commit cb073da

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

java/java.lsp.server/vscode/src/extension.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,12 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
830830
}
831831
};
832832

833+
context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel', async (projects?) => {
834+
testAdapter?.runTestsWithParallelParallel(projects);
835+
}));
836+
833837
context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test.parallel.createProfile', async (projects?) => {
834-
if (projects) {
835-
testAdapter?.registerRunInParallelProfile(projects);
836-
}
838+
testAdapter?.registerRunInParallelProfile(projects);
837839
}));
838840

839841
context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.run.test', async (uri, methodName?, launchConfiguration?, testInParallel?, projects?) => {

java/java.lsp.server/vscode/src/testAdapter.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
'use strict';
2020

21-
import { commands, debug, tests, workspace, CancellationToken, TestController, TestItem, TestRunProfileKind, TestRunRequest, Uri, TestRun, TestMessage, Location, Position, MarkdownString, TestRunProfile } from "vscode";
21+
import { commands, debug, tests, workspace, CancellationToken, TestController, TestItem, TestRunProfileKind, TestRunRequest, Uri, TestRun, TestMessage, Location, Position, MarkdownString, TestRunProfile, CancellationTokenSource } from "vscode";
2222
import * as path from 'path';
2323
import { asRange, TestCase, TestSuite } from "./protocol";
2424
import { COMMAND_PREFIX, listeners, TEST_PROGRESS_EVENT } from "./extension";
@@ -33,6 +33,7 @@ export class NbTestAdapter {
3333
private itemsToRun: Set<TestItem> | undefined;
3434
private started: boolean = false;
3535
private suiteStates: Map<TestItem, SuiteState>;
36+
private parallelRunProfile: TestRunProfile | undefined;
3637

3738
constructor() {
3839
this.testController = tests.createTestController('apacheNetBeansController', 'Apache NetBeans');
@@ -46,7 +47,15 @@ export class NbTestAdapter {
4647

4748
public registerRunInParallelProfile(projects: string[]) {
4849
const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects);
49-
this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
50+
this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
51+
this.testController.items.replace([]);
52+
this.load();
53+
}
54+
55+
public runTestsWithParallelParallel(projects?: string[]) {
56+
if (this.parallelRunProfile) {
57+
this.run(new TestRunRequest(undefined, undefined, this.parallelRunProfile), new CancellationTokenSource().token, true, projects);
58+
}
5059
}
5160

5261
async load(): Promise<void> {
@@ -198,7 +207,7 @@ export class NbTestAdapter {
198207
}
199208

200209
testProgress(suite: TestSuite): void {
201-
const currentModule = this.testController.items.get(this.getModuleName(suite));
210+
const currentModule = this.testController.items.get(suite.moduleName || "");
202211
const currentSuite = currentModule?.children.get(suite.name);
203212

204213
switch (suite.state) {
@@ -287,10 +296,11 @@ export class NbTestAdapter {
287296
}
288297

289298
updateTests(suite: TestSuite, testExecution?: boolean): void {
290-
const moduleName = this.getModuleName(suite);
299+
const moduleName = suite.moduleName || "";
291300
let currentModule = this.testController.items.get(moduleName);
292301
if (!currentModule) {
293-
currentModule = this.testController.createTestItem(moduleName, this.getNameWithIcon(moduleName, 'module'), this.getModulePath(suite));
302+
const parsedName = this.parseModuleName(moduleName);
303+
currentModule = this.testController.createTestItem(moduleName, this.getNameWithIcon(parsedName, 'module'), this.getModulePath(suite));
294304
this.testController.items.add(currentModule);
295305
}
296306

@@ -360,11 +370,19 @@ export class NbTestAdapter {
360370
currentModule.children.replace(suiteChildren);
361371
}
362372
}
363-
364-
getModuleName(suite: TestSuite): string {
365-
return suite.moduleName?.replace(":", "-") || "";
373+
374+
parseModuleName(moduleName: string): string {
375+
if (!this.parallelRunProfile) {
376+
return moduleName.replace(":", "-");
377+
}
378+
const index = moduleName.indexOf(":");
379+
if (index !== -1) {
380+
return moduleName.slice(index + 1);
381+
}
382+
const parts = moduleName.split("-");
383+
return parts[parts.length - 1];
366384
}
367-
385+
368386
getModulePath(suite: TestSuite): Uri {
369387
return Uri.parse(suite.modulePath || "");
370388
}

0 commit comments

Comments
 (0)