Skip to content

Add class name to the run/debug all tests #2416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/features/codeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ abstract class TestCodeLens extends OmniSharpCodeLens {
constructor(
range: protocol.V2.Range,
fileName: string,
public displayName: string,
public isTestContainer: boolean,
public testFramework: string,
public testMethodNames: string[]) {
Expand All @@ -53,23 +54,25 @@ class RunTestsCodeLens extends TestCodeLens {
constructor(
range: protocol.V2.Range,
fileName: string,
displayName: string,
isTestContainer: boolean,
testFramework: string,
testMethodNames: string[]) {

super(range, fileName, isTestContainer, testFramework, testMethodNames);
super(range, fileName, displayName, isTestContainer, testFramework, testMethodNames);
}
}

class DebugTestsCodeLens extends TestCodeLens {
constructor(
range: protocol.V2.Range,
fileName: string,
displayName: string,
isTestContainer: boolean,
testFramework: string,
testMethodNames: string[]) {

super(range, fileName, isTestContainer, testFramework, testMethodNames);
super(range, fileName, displayName, isTestContainer, testFramework, testMethodNames);
}
}

Expand Down Expand Up @@ -152,7 +155,7 @@ export default class OmniSharpCodeLensProvider extends AbstractProvider implemen
codeLens.command = {
title: pluralTitle,
command: pluralCommandName,
arguments: [codeLens.testMethodNames, codeLens.fileName, codeLens.testFramework]
arguments: [codeLens.displayName, codeLens.testMethodNames, codeLens.fileName, codeLens.testFramework]
};
}

Expand Down Expand Up @@ -188,8 +191,8 @@ function createCodeLensesForElement(element: Structure.CodeElement, fileName: st
let range = element.Ranges[SymbolRangeNames.Name];

if (range && testFramework && testMethodName) {
results.push(new RunTestsCodeLens(range, fileName, /*isTestContainer*/ false, testFramework, [testMethodName]));
results.push(new DebugTestsCodeLens(range, fileName, /*isTestContainer*/ false, testFramework, [testMethodName]));
results.push(new RunTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ false, testFramework, [testMethodName]));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does TS have the equivalent of C# named arguments? It would be neat to use those instead of the comment...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is object destructuring , but should we do that here microsoft/TypeScript#467 (comment)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting approach...

results.push(new DebugTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ false, testFramework, [testMethodName]));
}
}
else if (isValidClassForTestCodeLens(element)) {
Expand All @@ -210,8 +213,8 @@ function createCodeLensesForElement(element: Structure.CodeElement, fileName: st
}
}

results.push(new RunTestsCodeLens(range, fileName, /*isTestContainer*/ true, testFramework, testMethodNames));
results.push(new DebugTestsCodeLens(range, fileName, /*isTestContainer*/ true, testFramework, testMethodNames));
results.push(new RunTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ true, testFramework, testMethodNames));
results.push(new DebugTestsCodeLens(range, fileName, element.DisplayName,/*isTestContainer*/ true, testFramework, testMethodNames));
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/features/dotnetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export default class TestManager extends AbstractProvider {

let d4 = vscode.commands.registerCommand(
'dotnet.classTests.run',
async (methodsInClass, fileName, testFrameworkName) => this._runDotnetTestsInClass(methodsInClass, fileName, testFrameworkName));
async (className, methodsInClass, fileName, testFrameworkName) => this._runDotnetTestsInClass(className, methodsInClass, fileName, testFrameworkName));

let d5 = vscode.commands.registerCommand(
'dotnet.classTests.debug',
async (methodsInClass, fileName, testFrameworkName) => this._debugDotnetTestsInClass(methodsInClass, fileName, testFrameworkName));
async (className, methodsInClass, fileName, testFrameworkName) => this._debugDotnetTestsInClass(className, methodsInClass, fileName, testFrameworkName));

this._telemetryIntervalId = setInterval(() =>
this._reportTelemetry(), TelemetryReportingDelay);
Expand Down Expand Up @@ -164,10 +164,10 @@ export default class TestManager extends AbstractProvider {
}
}

private async _runDotnetTestsInClass(methodsInClass: string[], fileName: string, testFrameworkName: string) {
private async _runDotnetTestsInClass(className: string, methodsInClass: string[], fileName: string, testFrameworkName: string) {

//to do: try to get the class name here
this._eventStream.post(new DotNetTestsInClassRunStart());
this._eventStream.post(new DotNetTestsInClassRunStart(className));

const listener = this._server.onTestMessage(e => {
this._eventStream.post(new DotNetTestMessage(e.Message));
Expand Down Expand Up @@ -346,9 +346,9 @@ export default class TestManager extends AbstractProvider {
}
}

private async _debugDotnetTestsInClass(methodsToRun: string[], fileName: string, testFrameworkName: string) {
private async _debugDotnetTestsInClass(className: string, methodsToRun: string[], fileName: string, testFrameworkName: string) {

this._eventStream.post(new DotNetTestsInClassDebugStart());
this._eventStream.post(new DotNetTestsInClassDebugStart(className));

let { debugType, debugEventListener, targetFrameworkVersion } = await this._recordDebugAndGetDebugValues(fileName, testFrameworkName);

Expand Down
18 changes: 17 additions & 1 deletion src/observers/DotnetTestLoggerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { BaseEvent, DotNetTestRunStart, DotNetTestMessage, ReportDotNetTestResults, DotNetTestDebugStart, DotNetTestDebugWarning, DotNetTestDebugProcessStart, DotNetTestDebugComplete } from "../omnisharp/loggingEvents";
import { BaseEvent, DotNetTestRunStart, DotNetTestMessage, ReportDotNetTestResults, DotNetTestDebugStart, DotNetTestDebugWarning, DotNetTestDebugProcessStart, DotNetTestDebugComplete, DotNetTestsInClassDebugStart, DotNetTestsInClassRunStart } from "../omnisharp/loggingEvents";
import { BaseLoggerObserver } from "./BaseLoggerObserver";
import * as protocol from '../omnisharp/protocol';

Expand Down Expand Up @@ -32,6 +32,12 @@ export default class DotNetTestLoggerObserver extends BaseLoggerObserver {
case DotNetTestDebugComplete.name:
this.logger.appendLine("Debugging complete.\n");
break;
case DotNetTestsInClassDebugStart.name:
this.handleDotnetTestsInClassDebugStart(<DotNetTestsInClassDebugStart>event);
break;
case DotNetTestsInClassRunStart.name:
this.handleDotnetTestsInClassRunStart(<DotNetTestsInClassRunStart>event);
break;
}
}

Expand All @@ -49,6 +55,16 @@ export default class DotNetTestLoggerObserver extends BaseLoggerObserver {
this.logger.appendLine('');
}

private handleDotnetTestsInClassDebugStart(event: DotNetTestsInClassDebugStart) {
this.logger.appendLine(`----- Debugging tests in class ${event.className} -----`);
this.logger.appendLine('');
}

private handleDotnetTestsInClassRunStart(event: DotNetTestsInClassRunStart): any {
this.logger.appendLine(`----- Running tests in class "${event.className}" -----`);
this.logger.appendLine('');
}

private handleDotNetTestDebugProcessStart(event: DotNetTestDebugProcessStart) {
this.logger.appendLine(`Started debugging process #${event.targetProcessId}.`);
}
Expand Down
11 changes: 9 additions & 2 deletions src/omnisharp/loggingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ export class DotNetTestDebugProcessStart implements BaseEvent {
constructor(public targetProcessId: number) { }
}


export class DotNetTestsInClassRunStart implements BaseEvent {
constructor(public className: string) { }
}

export class DotNetTestsInClassDebugStart implements BaseEvent {
constructor(public className: string) { }
}

export class DebuggerPrerequisiteFailure extends EventWithMessage { }
export class DebuggerPrerequisiteWarning extends EventWithMessage { }
export class CommandDotNetRestoreProgress extends EventWithMessage { }
Expand Down Expand Up @@ -168,6 +177,4 @@ export class OmnisharpServerOnStop implements BaseEvent { }
export class OmnisharpServerOnStart implements BaseEvent { }
export class LatestBuildDownloadStart implements BaseEvent { }
export class OmnisharpRestart implements BaseEvent { }
export class DotNetTestsInClassRunStart implements BaseEvent { }
export class DotNetTestsInClassDebugStart implements BaseEvent { }
export class DotNetTestDebugComplete implements BaseEvent { }
4 changes: 2 additions & 2 deletions test/unitTests/logging/DotnetTestChannelObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ suite("DotnetTestChannelObserver", () => {
[
new DotNetTestRunStart("foo"),
new DotNetTestRunFailure("some failure"),
new DotNetTestsInClassRunStart(),
new DotNetTestsInClassRunStart("someclass"),
new DotNetTestDebugStart("foo"),
new DotNetTestsInClassDebugStart()
new DotNetTestsInClassDebugStart("someclass")
].forEach((event: BaseEvent) => {
test(`${event.constructor.name}: Channel is shown`, () => {
expect(hasShown).to.be.false;
Expand Down
15 changes: 13 additions & 2 deletions test/unitTests/logging/DotnetTestLoggerObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as chai from 'chai';
import { getNullChannel } from '../testAssets/Fakes';
import { EventWithMessage, DotNetTestDebugWarning, DotNetTestDebugStart, BaseEvent, DotNetTestRunStart, DotNetTestDebugProcessStart, DotNetTestMessage, DotNetTestDebugComplete, ReportDotNetTestResults } from '../../../src/omnisharp/loggingEvents';
import { EventWithMessage, DotNetTestDebugWarning, DotNetTestDebugStart, BaseEvent, DotNetTestRunStart, DotNetTestDebugProcessStart, DotNetTestMessage, DotNetTestDebugComplete, ReportDotNetTestResults, DotNetTestsInClassDebugStart, DotNetTestsInClassRunStart } from '../../../src/omnisharp/loggingEvents';
import DotNetTestLoggerObserver from '../../../src/observers/DotnetTestLoggerObserver';
import * as protocol from '../../../src/omnisharp/protocol';

Expand Down Expand Up @@ -42,7 +42,18 @@ suite(`${DotNetTestLoggerObserver.name}`, () => {
observer.post(event);
expect(appendedMessage).to.contain("foo");
});
});
});

[
new DotNetTestsInClassDebugStart("foo"),
new DotNetTestsInClassRunStart("foo")
].forEach((event: BaseEvent) => {
test(`${event.constructor.name}: Class name is logged`, () => {
expect(appendedMessage).to.be.empty;
observer.post(event);
expect(appendedMessage).to.contain("foo");
});
});

test(`${DotNetTestDebugProcessStart.name}: Target process id is logged`, () => {
let event = new DotNetTestDebugProcessStart(111);
Expand Down