Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Show test report from keyboard shorcut (microsoft#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Jul 7, 2020
1 parent 06e9628 commit 525907f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './src/testResultManager';
export * from './src/protocols';
export * from './src/utils/commandUtils';
export * from './src/testFileWatcher';
export * from './src/runners/runnerScheduler';
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
{
"command": "java.test.cancel",
"when": "java:serverMode != LightWeight"
},
{
"command": "java.test.show.report",
"when": "java:serverMode != LightWeight"
}
]
},
Expand Down Expand Up @@ -182,6 +186,11 @@
"title": "%contributes.commands.java.test.cancel.title%",
"category": "Java"
},
{
"command": "java.test.show.report",
"title": "%contributes.commands.java.test.show.report.title%",
"category": "Java"
},
{
"command": "java.test.explorer.refresh",
"title": "%contributes.commands.java.test.explorer.refresh.title%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"contributes.commands.java.test.explorer.debugAll.title": "Debug All Tests",
"contributes.commands.java.test.explorer.run.config.title": "Run With Configuration",
"contributes.commands.java.test.explorer.debug.config.title": "Debug With Configuration",
"contributes.commands.java.test.show.report.title": "Show Test Report",
"contributes.commands.java.test.cancel.title": "Cancel Test Job",
"contributes.commands.java.test.explorer.refresh.title": "Refresh",
"contributes.commands.java.test.config.migrate.title": "Migrate Deprecated 'launch.test.json'",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"contributes.commands.java.test.explorer.debugAll.title": "调试所有测试用例",
"contributes.commands.java.test.explorer.run.config.title": "根据配置文件运行",
"contributes.commands.java.test.explorer.debug.config.title": "根据配置文件调试",
"contributes.commands.java.test.show.report.title": "显示测试报告",
"contributes.commands.java.test.cancel.title": "取消测试任务",
"contributes.commands.java.test.explorer.refresh.title": "刷新",
"contributes.commands.java.test.config.migrate.title": "迁移已弃用的 'launch.test.json' 文件",
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function doActivate(_operationId: string, context: ExtensionContext): Prom
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.DEBUG_ALL_TEST_FROM_EXPLORER, async () => await debugTestsFromExplorer()),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.RUN_TEST_FROM_EXPLORER, async (node?: ITestItem, launchConfiguration?: DebugConfiguration) => await runTestsFromExplorer(node, launchConfiguration)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.DEBUG_TEST_FROM_EXPLORER, async (node?: ITestItem, launchConfiguration?: DebugConfiguration) => await debugTestsFromExplorer(node, launchConfiguration)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.SHOW_TEST_REPORT, async (tests: ITestResult[]) => await testReportProvider.report(tests)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.SHOW_TEST_REPORT, async (tests?: ITestResult[]) => await testReportProvider.report(tests)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.SHOW_TEST_OUTPUT, () => showOutputChannel()),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.OPEN_TEST_LOG, async () => await openLogFile(storagePath)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_CANCEL, async () => await runnerScheduler.cleanUp(true /* isCancel */)),
Expand Down
12 changes: 12 additions & 0 deletions src/runners/runnerScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class RunnerScheduler {
private _context: ExtensionContext;
private _isRunning: boolean;
private _runnerMap: Map<BaseRunner, ITestItem[]> | undefined;
private _executionCache: IExecutionCache;

public initialize(context: ExtensionContext): void {
this._context = context;
Expand All @@ -35,6 +36,7 @@ class RunnerScheduler {
}

this._isRunning = true;
this._executionCache = Object.assign({}, {context: runnerContext});
let allIds: Set<string> = new Set<string>();

try {
Expand All @@ -60,6 +62,7 @@ class RunnerScheduler {
testStatusBarProvider.showTestResult(finalResults);
testCodeLensController.refresh();
this.showReportIfNeeded(finalResults);
this._executionCache.results = finalResults;
} catch (error) {
logger.error(error.toString());
uiUtils.showError(error);
Expand All @@ -68,6 +71,10 @@ class RunnerScheduler {
}
}

public getExecutionCache(): IExecutionCache {
return this._executionCache;
}

public async cleanUp(isCancel: boolean): Promise<void> {
try {
const promises: Array<Promise<void>> = [];
Expand Down Expand Up @@ -177,4 +184,9 @@ class RunnerScheduler {
}
}

export interface IExecutionCache {
context: IRunnerContext;
results?: ITestResult[];
}

export const runnerScheduler: RunnerScheduler = new RunnerScheduler();
11 changes: 10 additions & 1 deletion src/testReportProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { JavaTestRunnerCommands } from './constants/commands';
import { logger } from './logger/logger';
import { ILocation, ITestItem } from './protocols';
import { ITestResult, TestStatus } from './runners/models';
import { IExecutionCache, runnerScheduler } from './runners/runnerScheduler';
import { testItemModel } from './testItemModel';
import { searchTestLocation } from './utils/commandUtils';
import { getReportPosition } from './utils/settingUtils';
Expand All @@ -26,7 +27,15 @@ class TestReportProvider implements Disposable {
this.resourceBasePath = path.join(this.context.extensionPath, 'resources', 'templates');
}

public async report(tests: ITestResult[]): Promise<void> {
public async report(tests?: ITestResult[]): Promise<void> {
const executionCache: IExecutionCache = runnerScheduler.getExecutionCache();
if (executionCache.results) {
tests = executionCache.results;
}
if (!tests || tests.length === 0) {
return;
}

const position: ViewColumn = getReportPosition();
if (!this.panel) {
this.panel = window.createWebviewPanel('testRunnerReport', 'Java Test Report', position, {
Expand Down
6 changes: 3 additions & 3 deletions src/testStatusBarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class TestStatusBarProvider implements Disposable {
}

public showRunningTest(): void {
this.update('$(sync~spin) Running tests...', 'View test output', JavaTestRunnerCommands.SHOW_TEST_OUTPUT);
this.update('$(sync~spin) Running tests...', 'Show test output', JavaTestRunnerCommands.SHOW_TEST_OUTPUT);
}

public showFailure(): void {
this.update('$(issue-opened) Failed to run tests', 'View test output', JavaTestRunnerCommands.SHOW_TEST_OUTPUT);
this.update('$(issue-opened) Failed to run tests', 'Show test output', JavaTestRunnerCommands.SHOW_TEST_OUTPUT);
}

public showTestResult(results: ITestResult[]): void {
Expand All @@ -40,7 +40,7 @@ class TestStatusBarProvider implements Disposable {
}
}

this.update(`$(x) ${failedNum} $(check) ${passedNum}`, 'View test report', JavaTestRunnerCommands.SHOW_TEST_REPORT, [results]);
this.update(`$(x) ${failedNum} $(check) ${passedNum}`, 'Show test report', JavaTestRunnerCommands.SHOW_TEST_REPORT, [results]);
}

public update(text: string, tooltip?: string, command?: string, args?: any[]): void {
Expand Down
6 changes: 5 additions & 1 deletion test/maven-junit4-suite/codelens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as assert from 'assert';
import { CodeLens, Command, commands, TextDocument, window, workspace, extensions } from 'vscode';
import { ITestResult, TestCodeLensProvider, testResultManager, TestStatus, ITestItem } from '../../extension.bundle';
import { IExecutionCache, ITestResult, runnerScheduler, TestCodeLensProvider, testResultManager, TestStatus, ITestItem } from '../../extension.bundle';
import { Token, Uris } from '../shared';

suite('Code Lens Tests', function() {
Expand Down Expand Up @@ -40,6 +40,10 @@ suite('Code Lens Tests', function() {
const passedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.TestAnnotation#shouldPass`);
assert.equal(passedDetail!.status, TestStatus.Pass, 'Should have passed case');
assert.ok(passedDetail!.duration !== undefined, 'Should have execution time');

const executionCache: IExecutionCache = runnerScheduler.getExecutionCache();
assert.ok(executionCache.context != undefined);
assert.equal(executionCache.results!.length, 2);
});

test("Code Lens should be present for JUnit 4's @Theory annotation", async function() {
Expand Down

0 comments on commit 525907f

Please sign in to comment.