Skip to content
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

Add Show Test Output feature #305

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ npm-debug.log
yarn.*
[Bb]in/
[Oo]bj/
lcov.info
lcov.info
.vscode-test/**
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"version": "0.1.0",
"configurations": [

{
"name": "Launch Extension (xunit)",
"type": "extensionHost",
Expand Down Expand Up @@ -118,6 +119,17 @@
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm"
},
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
],
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm"
}
]
}
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
{
"command": "dotnet-test-explorer.openPanel",
"title": "Open Tests Panel"
},
{
"command": "dotnet-test-explorer.showTestOutput",
"title": "Show Test Output",
"icon": {
"light": "resources/light/log.svg",
"dark": "resources/dark/log.svg"
}
}
],
"menus": {
Expand Down Expand Up @@ -143,7 +151,7 @@
{
"command": "dotnet-test-explorer.runTest",
"when": "view == dotnetTestExplorer",
"group": "inline"
"group": "inline@0"
},
{
"command": "dotnet-test-explorer.gotoTest",
Expand All @@ -154,6 +162,11 @@
"command": "dotnet-test-explorer.debugTest",
"when": "viewItem == test",
"group": "dotnetTestExplorer@2"
},
{
"command": "dotnet-test-explorer.showTestOutput",
"when": "viewItem == test",
"group": "inline@1"
}
],
"editor/context": [
Expand Down Expand Up @@ -294,7 +307,8 @@
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"test": "node ./out/test/runTest.js",
"tslint": "tslint -t verbose src/**/*.ts"
"tslint": "tslint -t verbose src/**/*.ts",
"precompile": "node ./test/restorePackages.js"
},
"devDependencies": {
"@types/glob": "^7.1.1",
Expand Down
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TestNode } from "./testNode";
import { TestStatusCodeLensProvider } from "./testStatusCodeLensProvider";
import { Utility } from "./utility";
import { Watch } from "./watch";
import { TestResultDocumentContentProvider } from './testResultDocumentContentProvider';

export function activate(context: vscode.ExtensionContext) {
const testDirectories = new TestDirectories();
Expand Down Expand Up @@ -115,6 +116,12 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.window.onDidCloseTerminal((closedTerminal: vscode.Terminal) => {
Executor.onDidCloseTerminal(closedTerminal);
}));

context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider("dotnet-test-explorer.testResult", new TestResultDocumentContentProvider()));

context.subscriptions.push(vscode.commands.registerCommand("dotnet-test-explorer.showTestOutput", (test: TestNode) => {
testCommands.showTestOutput(test);
}));
}

export function deactivate() {
Expand Down
16 changes: 16 additions & 0 deletions src/testCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class TestCommands implements Disposable {
private onNewTestResultsEmitter = new EventEmitter<ITestResult>();
private onBuildFailedEmitter = new EventEmitter<ITestRunContext>();
private lastRunTestContext: ITestRunContext = null;
private lastRunTestResults: TestResult[] = [];
private testResultsFolder: string;
private testResultsFolderWatcher: any;

Expand Down Expand Up @@ -203,6 +204,7 @@ export class TestCommands implements Disposable {
allTestResults.push(...testResults);
}
this.sendNewTestResults({ clearPreviousTestResults: testName === "", testResults: allTestResults });
this.lastRunTestResults = allTestResults;
} catch (err) {
Logger.Log(`Error while executing test command: ${err}`);
if (err.message === "Build command failed") {
Expand Down Expand Up @@ -296,4 +298,18 @@ export class TestCommands implements Disposable {
});
});
}

public async showTestOutput(test: TestNode) {
const testResult = this.lastRunTestResults.find(x => x.name == test.name);
if (!testResult) vscode.window.showInformationMessage(`Result not found for test '${test.name}'. Make sure the test is included in a test run.`);

const uri = vscode.Uri.parse(`dotnet-test-explorer.testResult:${testResult?.name}`)
.with({
query: testResult.stdout,
fragment: testResult.outcome
});

const doc = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(doc, { preview: true });
}
}
11 changes: 10 additions & 1 deletion src/testResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class TestResult {
private className: string;
private method: string;

public constructor(private _testId: string, private _outcome: string, private _message: string, private _stackTrace: string) {
public constructor(private _testId: string, private _outcome: string, private _message: string, private _stackTrace: string, private _stdout: string) {
}

public get fullName(): string {
Expand All @@ -30,6 +30,15 @@ export class TestResult {
return this._stackTrace;
}

public get stdout(): string {
return this._stdout
|| `${this._message}\r\n${this._stackTrace}` ;
}

public get name(): string {
return this.method;
}

public matches(className: string, method: string): boolean {
return this.fullName.indexOf(className + "." + method) > -1;
}
Expand Down
16 changes: 16 additions & 0 deletions src/testResultDocumentContentProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
import { TextDocumentContentProvider, Uri, EventEmitter } from 'vscode';

export class TestResultDocumentContentProvider implements TextDocumentContentProvider {
onDidChangeEmitter = new EventEmitter<Uri>();
onDidChange = this.onDidChangeEmitter.event;

provideTextDocumentContent(uri: Uri): string {
return `
Test Name: ${uri.path}
Test Outcome: ${uri.fragment}
Standard Output:
${uri.query}
`;
}
}
1 change: 1 addition & 0 deletions src/testResultsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function parseUnitTestResults(xml: Element): TestResult[] {
getAttributeValue(nodes[i], "outcome"),
getTextContentForTag(nodes[i], "Message"),
getTextContentForTag(nodes[i], "StackTrace"),
getTextContentForTag(nodes[i], "StdOut"),
));
}

Expand Down
2 changes: 1 addition & 1 deletion test/problems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ suite("Problems tests", () => {
});

function GetTestResult(id: string, outcome: string, message: string, stackTrace: string) {
return new TestResult(id, outcome, message, stackTrace);
return new TestResult(id, outcome, message, stackTrace, "");
}
8 changes: 8 additions & 0 deletions test/restorePackages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let { exec } = require('child_process');
let log = (err, stdout, stderr) => console.log(stdout)

exec("dotnet restore ./test/fsxunittests/FSharpTests.fsproj", log);
exec("dotnet restore ./test/mstest/MSTestTests.csproj", log);
exec("dotnet restore ./test/nunit/NunitTests.csproj", log);
exec("dotnet restore ./test/nunitNet5/NunitTests.csproj", log);
exec("dotnet restore ./test/xunittests/XunitTests.csproj", log);
2 changes: 1 addition & 1 deletion test/testNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ suite("Icon tests", () => {
});

function GetTestResult(id: string, outcome: string, className: string, method: string) {
const testResult = new TestResult(id, outcome, "", "");
const testResult = new TestResult(id, outcome, "", "", "");
testResult.updateName(className, method);
return testResult;
}