Skip to content

Commit

Permalink
Dispatch additional test events
Browse files Browse the repository at this point in the history
  • Loading branch information
petrovic-d committed Jan 3, 2025
1 parent e60cf75 commit 3e3e7b5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
5 changes: 5 additions & 0 deletions java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export let client: Promise<NbLanguageClient>;
export let clientRuntimeJDK : string | null = null;
export const MINIMAL_JDK_VERSION = 17;
export const TEST_PROGRESS_EVENT: string = "testProgress";
const TEST_ADAPTER_CREATED_EVENT: string = "testAdapterCreated";
let testAdapter: NbTestAdapter | undefined;
let nbProcess : ChildProcess | null = null;
let debugPort: number = -1;
Expand Down Expand Up @@ -1534,6 +1535,10 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
c.start().then(() => {
if (isJavaSupportEnabled()) {
testAdapter = new NbTestAdapter();
const testAdapterCreatedListeners = listeners.get(TEST_ADAPTER_CREATED_EVENT);
testAdapterCreatedListeners?.forEach(listener => {
commands.executeCommand(listener);
})
}
c.onNotification(StatusMessageRequest.type, showStatusBarMessage);
c.onRequest(HtmlPageRequest.type, showHtmlPage);
Expand Down
61 changes: 50 additions & 11 deletions java/java.lsp.server/vscode/src/testAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export class NbTestAdapter {
}

public registerRunInParallelProfile(projects: string[]) {
const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects);
this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
if (!this.parallelRunProfile) {
const runHandler = (request: TestRunRequest, cancellation: CancellationToken) => this.run(request, cancellation, true, projects);
this.parallelRunProfile = this.testController.createRunProfile("Run Tests In Parallel", TestRunProfileKind.Run, runHandler, true);
}
this.testController.items.replace([]);
this.load();
}
Expand Down Expand Up @@ -165,20 +167,36 @@ export class NbTestAdapter {

dispatchTestEvent(state: SuiteState, testItem: TestItem): void {
if (testItem.parent && testItem.children.size > 0) {
this.dispatchEvent({
name: testItem.id,
moduleName: testItem.parent.id,
modulePath: testItem.parent.uri?.path,
state,
});
if (testItem.id.includes(":") && testItem.parent.parent) {
// special case when parameterized test
const testEvent = this.getParametrizedTestEvent(state, testItem);
if (!testEvent) return;

this.dispatchEvent(testEvent);
} else {
this.dispatchEvent({
name: testItem.id,
moduleName: testItem.parent.id,
modulePath: testItem.parent.uri?.path,
state,
});
}
} else if (testItem.children.size === 0) {
const testSuite = testItem.parent;
const parentState = testSuite && this.suiteStates.get(testSuite) ? this.suiteStates.get(testSuite) : state;
if (testSuite) {
let moduleName = testSuite.parent?.id;
let modulePath = testSuite.parent?.uri?.path;
if (testSuite.id.includes(":") && testSuite.parent?.parent) {
// special case when parameterized test
moduleName = testSuite.parent.parent.id;
modulePath = testSuite.parent.parent.uri?.path;
}
const testSuiteEvent: any = {
name: testSuite.id,
moduleName: testSuite.parent?.id,
modulePath: testSuite.parent?.uri?.path,
state,
moduleName,
modulePath,
state: parentState,
tests: []
}
testSuite?.children.forEach(suite => {
Expand All @@ -199,6 +217,27 @@ export class NbTestAdapter {
}
}

getParametrizedTestEvent(state: SuiteState, testItem: TestItem): any {
if (!testItem.parent || !testItem.parent.parent) {
return undefined;
}
let name = testItem.parent.id;
const idx = name.indexOf(':');
return {
name,
moduleName: testItem.parent.parent.id,
modulePath: testItem.parent.parent.uri?.path,
state,
tests: [
{
id: name,
name: name.slice(idx + 1),
state
}
]
}
}

dispatchEvent(event: any): void {
const testProgressListeners = listeners.get(TEST_PROGRESS_EVENT);
testProgressListeners?.forEach(listener => {
Expand Down

0 comments on commit 3e3e7b5

Please sign in to comment.