Skip to content
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
3 changes: 1 addition & 2 deletions src/runners/baseRunner/BaseRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { IExecutionConfig } from '../../runConfigs';
import * as classpathUtils from '../../utils/classpathUtils';
import { resolveRuntimeClassPath } from '../../utils/commandUtils';
import { killProcess } from '../../utils/cpUtils';
import { resolveWorkingDirectory } from '../../utils/settingUtils';
import { ITestRunner } from '../ITestRunner';
import { ITestResult } from '../models';
import { BaseRunnerResultAnalyzer } from './BaseRunnerResultAnalyzer';
Expand Down Expand Up @@ -57,7 +56,7 @@ export abstract class BaseRunner implements ITestRunner {

public async run(): Promise<ITestResult[]> {
const commandParams: string[] = await this.constructCommandParams();
const options: cp.SpawnOptions = { cwd: this.config ? resolveWorkingDirectory(this.tests[0].uri, this.config.workingDirectory) : undefined, env: process.env };
const options: cp.SpawnOptions = { cwd: this.config ? this.config.workingDirectory : undefined, env: process.env };
if (this.config && this.config.env) {
options.env = {...this.config.env, ...options.env};
}
Expand Down
6 changes: 4 additions & 2 deletions src/runners/runnerExecutor.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 { CancellationToken, ExtensionContext, Progress, ProgressLocation, window } from 'vscode';
import { CancellationToken, ExtensionContext, Progress, ProgressLocation, Uri, window } from 'vscode';
import { testCodeLensProvider } from '../codeLensProvider';
import { logger } from '../logger/logger';
import { ITestItem, TestKind } from '../protocols';
Expand All @@ -10,6 +10,7 @@ import { testConfigManager } from '../testConfigManager';
import { testReportProvider } from '../testReportProvider';
import { testResultManager } from '../testResultManager';
import { testStatusBarProvider } from '../testStatusBarProvider';
import { resolve } from '../utils/settingUtils';
import { ITestRunner } from './ITestRunner';
import { JUnit4Runner } from './junit4Runner/Junit4Runner';
import { JUnit5Runner } from './junit5Runner/JUnit5Runner';
Expand Down Expand Up @@ -43,13 +44,14 @@ class RunnerExecutor {
logger.info('Test job is canceled.');
continue;
}

await window.withProgress(
{ location: ProgressLocation.Notification, cancellable: true },
async (progress: Progress<any>, token: CancellationToken): Promise<void> => {
token.onCancellationRequested(() => {
this.cleanUp(true /* isCancel */);
});
await runner.setup(tests, isDebug, config);
await runner.setup(tests, isDebug, resolve(config, Uri.parse(tests[0].uri)));
testStatusBarProvider.showRunningTest();
progress.report({ message: 'Running tests...'});
await runner.execPreLaunchTaskIfExist();
Expand Down
54 changes: 46 additions & 8 deletions src/utils/settingUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as _ from 'lodash';
import { Uri, ViewColumn, workspace, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
import { DEFAULT_LOG_LEVEL, DEFAULT_REPORT_POSITION, LOG_LEVEL_SETTING_KEY, REPORT_POSITION_SETTING_KEY } from '../constants/configs';
import { logger } from '../logger/logger';
import { IExecutionConfig } from '../runConfigs';

export function getReportPosition(): ViewColumn {
const config: WorkspaceConfiguration = workspace.getConfiguration();
Expand All @@ -16,14 +18,50 @@ export function getLogLevel(): string {
}

const workspaceRegexp: RegExp = /\$\{workspacefolder\}/i;
export function resolveWorkingDirectory(testUriString: string, cwd: string | undefined): string | undefined {
if (cwd && workspaceRegexp.test(cwd)) {
const workspaceFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(Uri.parse(testUriString));
if (workspaceFolder) {
return cwd.replace(workspaceRegexp, workspaceFolder.uri.fsPath);
export function resolve(config: IExecutionConfig, uri: Uri): IExecutionConfig {
const resolvedConfig: IExecutionConfig = {};
const workspaceFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(uri);
if (!workspaceFolder) {
logger.error(`Failed to parse the working directory for test: ${uri}`);
return config;
}

if (config.workingDirectory) {
if (workspaceRegexp.test(config.workingDirectory)) {
resolvedConfig.workingDirectory = config.workingDirectory.replace(workspaceRegexp, workspaceFolder.uri.fsPath);
}
}

if (config.args) {
resolvedConfig.args = [];
for (const arg of config.args) {
if (needResolve(arg)) {
resolvedConfig.args.push(arg.replace(workspaceRegexp, workspaceFolder.uri.fsPath));
}
}
}

if (config.vmargs) {
resolvedConfig.vmargs = [];
for (const vmarg of config.vmargs as string[]) {
if (needResolve(vmarg)) {
resolvedConfig.vmargs.push(vmarg.replace(workspaceRegexp, workspaceFolder.uri.fsPath));
}
}
}

if (config.env) {
resolvedConfig.env = {};
for (const key of Object.keys(config.env)) {
if (needResolve(config.env[key])) {
resolvedConfig.env[key] = config.env[key].replace(workspaceRegexp, workspaceFolder.uri.fsPath);
}
}
logger.error(`Failed to parse the working directory for test: ${testUriString}`);
return undefined;
}
return cwd;

return resolvedConfig;
}

function needResolve(value: any): boolean {
return _.isString(value) && workspaceRegexp.test(value);
}