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

Can navigate to source from TestNG's stacktrace #1256

Merged
merged 1 commit into from
Aug 3, 2021
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
8 changes: 0 additions & 8 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@
// Licensed under the MIT license.

export { activate, deactivate } from './src/extension';
export * from './src/codelens/TestCodeLensProvider';
export * from './src/codelens/TestCodeLensController';
export * from './src/runners/models';
export * from './src/testResultManager';
export * from './src/protocols';
export * from './src/utils/commandUtils';
export * from './src/testFileWatcher';
export * from './src/runners/runnerScheduler';
export * from './src/provider/testSourceProvider';
30 changes: 23 additions & 7 deletions src/runners/testngRunner/TestNGRunnerResultAnalyzer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { Location, TestItem, TestMessage, TestResultState } from 'vscode';
import { Location, MarkdownString, TestItem, TestMessage, TestResultState } from 'vscode';
import { dataCache } from '../../controller/testItemDataCache';
import { IRunTestContext, TestLevel } from '../../types';
import { IRunnerResultAnalyzer } from '../baseRunner/IRunnerResultAnalyzer';
Expand Down Expand Up @@ -82,24 +82,40 @@ export class TestNGRunnerResultAnalyzer implements IRunnerResultAnalyzer {
return;
}
this.currentTestState = TestResultState.Failed;
const testMessages: TestMessage[] = [];
if (outputData.attributes.message) {
const message: TestMessage = new TestMessage(outputData.attributes.message);
const message: TestMessage = new TestMessage(outputData.attributes.message.trim());
if (item.uri && item.range) {
message.location = new Location(item.uri, item.range);
}
setTestState(this.testContext.testRun, item, this.currentTestState, message);
testMessages.push(message);
}

if (outputData.attributes.trace) {
const trace: TestMessage = new TestMessage(outputData.attributes.trace);
const traceString: string = outputData.attributes.trace.trim();
const markdownTrace: MarkdownString = new MarkdownString();
markdownTrace.isTrusted = true;
const traceRegExp: RegExp = /(\s?at\s+)([\w$\\.]+\/)?((?:[\w$]+\.)+[<\w$>]+)\(([\w-$]+\.java):(\d+)\)/;
for (const line of traceString.split(/\r?\n/)) {
const traceResults: RegExpExecArray | null = traceRegExp.exec(line);
if (traceResults && traceResults.length === 6) {
markdownTrace.appendText(traceResults[1]);
markdownTrace.appendMarkdown(`${(traceResults[2] || '') + traceResults[3]}([${traceResults[4]}:${traceResults[5]}](command:_java.test.openStackTrace?${encodeURIComponent(JSON.stringify([data, this.projectName]))}))`);
} else {
// in case the message contains message like: 'expected: <..> but was: <..>'
markdownTrace.appendText(line.replace(/</g, '&lt;').replace(/>/g, '&gt;'));
}
markdownTrace.appendText('\n');
}
const testMessage: TestMessage = new TestMessage(markdownTrace);
if (item.uri && item.range) {
trace.location = new Location(item.uri, item.range);
testMessage.location = new Location(item.uri, item.range);
}
setTestState(this.testContext.testRun, item, this.currentTestState, trace);
testMessages.push(testMessage);
}

const duration: number = Number.parseInt(outputData.attributes.duration, 10);
setTestState(this.testContext.testRun, item, this.currentTestState, undefined, duration);
setTestState(this.testContext.testRun, item, this.currentTestState, testMessages, duration);
} else if (outputData.name === TEST_FINISH) {
const item: TestItem | undefined = this.getTestItem(data);
if (!item) {
Expand Down
15 changes: 1 addition & 14 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

//@ts-check
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

/**@type {import('webpack').Configuration}*/
const config = {
Expand Down Expand Up @@ -38,18 +37,6 @@ const config = {
loader: 'ts-loader',
}]
}]
},
plugins: [
// Copy files to dist folder where the runtime can find them
// @ts-ignore
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, 'out', 'test'),
to: path.join(__dirname, 'dist', 'test')
},
]
}),
],
}
}
module.exports = config;