Skip to content

Commit 4908088

Browse files
committed
Add preLaunchTask option for TestRunner
1 parent 3d10549 commit 4908088

File tree

9 files changed

+44
-23
lines changed

9 files changed

+44
-23
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,12 @@ Lightweight and efficient, DotRush is designed to be fast and responsive.
9494

9595
 You can change the debugger options in the VSCode settings.
9696

97-
![image](https://github.com/JaneySprings/DotRush/raw/main/assets/image4.jpg)
97+
![image](https://github.com/JaneySprings/DotRush/raw/main/assets/image4.jpg)
98+
99+
## Profiling .NET Core Applications
100+
 To profile your .NET Core applications, you can use the built-in **dotnet-trace** and **dotnet-gcdump** tools. You can attach the profiler to a running process by executing the `DotRush: Attach Trace Profiler` or `DotRush: Create Heap Dump` commands. Also you can use the following buttons in the debugger toolbar if you have the **.NET Core Debugger** running:
101+
102+
![image](https://github.com/JaneySprings/DotRush/raw/main/assets/image7.jpg)
103+
104+
- For the `trace` report, you can use the [Speedscope in VSCode](https://marketplace.visualstudio.com/items?itemName=sransara.speedscope-in-vscode) extension to view it. Alternatively, you can upload it directly to the [speedscope](https://www.speedscope.app) site.
105+
- For the `gcdump` report, you can use the [dotnet-heapview](https://github.com/1hub/dotnet-heapview) or _Visual Studio for Windows_.

assets/image7.jpg

15.8 KB
Loading

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,6 @@
503503
"default": true,
504504
"description": "%configuration.description.debugger.automaticSourcelinkDownload%"
505505
},
506-
"dotrush.debugger.automaticLaunchSettingsLoad": {
507-
"type": "boolean",
508-
"default": true,
509-
"description": "%configuration.description.debugger.automaticLaunchSettingsLoad%"
510-
},
511506
"dotrush.debugger.symbolSearchPaths": {
512507
"type": "array",
513508
"description": "%configuration.description.debugger.symbolSearchPaths%",
@@ -576,6 +571,10 @@
576571
"experimental"
577572
],
578573
"description": "%configuration.description.testExplorer.skipInitialPauseEvent%"
574+
},
575+
"dotrush.testExplorer.preLaunchTask": {
576+
"type": "string",
577+
"description": "%configuration.description.testExplorer.preLaunchTask%"
579578
}
580579
}
581580
}

package.nls.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"configuration.description.debugger.stepOverPropertiesAndOperators": "Step over properties and operators.",
3333
"configuration.description.debugger.searchMicrosoftSymbolServer": "Search Microsoft Symbol Server for missing PDBs.",
3434
"configuration.description.debugger.automaticSourcelinkDownload": "Automatically download source files from SourceLink.",
35-
"configuration.description.debugger.automaticLaunchSettingsLoad": "Automatically load launchSettings.json file from the Properties folder of the startup project.",
3635
"configuration.description.debugger.symbolSearchPaths": "Additional symbol search paths.",
3736
"configuration.description.debugger.console": "Console to use for debugging console applications.",
3837

@@ -42,5 +41,6 @@
4241
"configuration.description.msbuild.additionalTestArguments": "Additional arguments to pass to the test command.",
4342

4443
"configuration.description.testExplorer.autoRefreshTests": "Automatically refresh tests on source code save.",
45-
"configuration.description.testExplorer.skipInitialPauseEvent": "Skip the initial pause event when starting the tests debugging. This option will be ignored for netcoredbg."
44+
"configuration.description.testExplorer.skipInitialPauseEvent": "Skip the initial pause event when starting the tests debugging. This option will be ignored for netcoredbg.",
45+
"configuration.description.testExplorer.preLaunchTask": "Task to run before launching the test run."
4646
}

src/VSCode/controllers/testExplorerController.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ProcessArgumentBuilder } from '../interop/processArgumentBuilder';
12
import { DotNetTaskProvider } from '../providers/dotnetTaskProvider';
23
import { TestExtensions } from '../models/test';
34
import { Interop } from '../interop/interop';
@@ -57,24 +58,28 @@ export class TestExplorerController {
5758
}
5859
private static async runTests(request: vscode.TestRunRequest, token: vscode.CancellationToken): Promise<void> {
5960
TestExplorerController.convertTestRequest(request).forEach(async (filters, project) => {
61+
const preLaunchTask = await Extensions.getTask(Extensions.getSetting<string>(res.configIdTestExplorerPreLaunchTask));
6062
const testReport = path.join(TestExplorerController.testsResultDirectory, `${project.label}.trx`);
6163
if (fs.existsSync(testReport))
6264
vscode.workspace.fs.delete(vscode.Uri.file(testReport));
6365

64-
const testArguments: string[] = ['--logger', `'trx;LogFileName=${testReport}'`];
65-
if (filters.length > 0) {
66-
testArguments.push('--filter');
67-
testArguments.push(`'${filters.join('|')}'`);
68-
}
66+
const testArguments = new ProcessArgumentBuilder('test')
67+
.append('--logger').append(`'trx;LogFileName=${testReport}'`);
68+
69+
testArguments.conditional('--no-build', () => preLaunchTask !== undefined);
70+
testArguments.conditional('--filter', () => filters.length > 0);
71+
testArguments.conditional(`'${filters.join('|')}'`, () => filters.length > 0);
6972

7073
const testRun = TestExplorerController.controller.createTestRun(request);
74+
await Extensions.waitForTask(preLaunchTask);
7175
await Extensions.waitForTask(DotNetTaskProvider.getTestTask(project.uri!.fsPath, testArguments));
7276
await TestExplorerController.publishTestResults(testRun, project, testReport);
7377
});
7478
}
7579
private static async debugTests(request: vscode.TestRunRequest, token: vscode.CancellationToken): Promise<void> {
7680
TestExplorerController.convertTestRequest(request).forEach(async (filters, project) => {
77-
const executionSuccess = await Extensions.waitForTask(DotNetTaskProvider.getBuildTask(project.uri!.fsPath));
81+
const preLaunchTask = await Extensions.getTask(Extensions.getSetting<string>(res.configIdTestExplorerPreLaunchTask));
82+
const executionSuccess = await Extensions.waitForTask(preLaunchTask ?? DotNetTaskProvider.getBuildTask(project.uri!.fsPath));
7883
if (!executionSuccess || token.isCancellationRequested)
7984
return;
8085

src/VSCode/extensions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ export class Extensions {
9696
await Promise.all(slice.map(action));
9797
}
9898
}
99-
public static async waitForTask(task: vscode.Task): Promise<boolean> {
99+
public static async waitForTask(task: vscode.Task | undefined): Promise<boolean> {
100+
if (task === undefined)
101+
return false;
102+
100103
const execution = await vscode.tasks.executeTask(task);
101104
const executionExitCode = await new Promise<number>((resolve) => {
102105
const disposable = vscode.tasks.onDidEndTaskProcess(e => {
@@ -108,6 +111,13 @@ export class Extensions {
108111
});
109112
return executionExitCode === 0;
110113
}
114+
public static async getTask(taskName: string | undefined): Promise<vscode.Task | undefined> {
115+
if (taskName === undefined)
116+
return undefined;
117+
118+
const tasks = await vscode.tasks.fetchTasks();
119+
return tasks.find(task => task.name === taskName);
120+
}
111121
public static getCurrentWorkingDirectory(): string | undefined {
112122
if (vscode.workspace.workspaceFile !== undefined)
113123
return path.dirname(vscode.workspace.workspaceFile.fsPath);

src/VSCode/providers/dotnetDebugConfigurationProvider.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ export class DotNetDebugConfigurationProvider implements vscode.DebugConfigurati
3131
}
3232

3333
private static provideDebuggerConfiguration(config: vscode.DebugConfiguration) {
34-
// https://github.com/JaneySprings/DotRush/issues/22
35-
if (config.launchSettingsFilePath === undefined && Extensions.getSetting<boolean>(res.configIdDebuggerAutomaticLaunchSettingsLoad))
34+
if (config.launchSettingsFilePath === undefined)
3635
config.launchSettingsFilePath = DebugAdapterController.getLaunchSettingsPath();
37-
if (config.launchSettingsFilePath !== undefined && Extensions.onVSCode(false, true /* netcoredbg only */)) {
36+
if (config.launchSettingsFilePath !== undefined && Extensions.onVSCode(false, true /* https://github.com/JaneySprings/DotRush/issues/22 */)) {
3837
const profile = DebugAdapterController.getLaunchProfile(config.launchSettingsFilePath, config.launchSettingsProfile);
3938
DotNetDebugConfigurationProvider.provideDebuggerConfigurationFromProfile(config, profile);
4039
}
@@ -61,7 +60,7 @@ export class DotNetDebugConfigurationProvider implements vscode.DebugConfigurati
6160

6261
config.cwd = profile.workingDirectory;
6362
config.program = profile.executablePath;
64-
config.args = profile.commandLineArgs;
63+
config.args = [profile.commandLineArgs]; //TODO: We need to split the command line args
6564
config.env = profile.environmentVariables;
6665

6766
if (profile.applicationUrl !== undefined)

src/VSCode/providers/dotnetTaskProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export class DotNetTaskProvider implements vscode.TaskProvider {
3131
];
3232
}
3333

34-
public static getTestTask(projectFile: string, args: string[] | undefined = undefined): vscode.Task {
35-
return DotNetTaskProvider.getTask({ type: res.taskDefinitionId, args: args }, projectFile, DotNetTarget.Test, StatusBarController.activeConfiguration);
34+
public static getTestTask(projectFile: string, builder: ProcessArgumentBuilder | undefined = undefined): vscode.Task {
35+
return DotNetTaskProvider.getTask({ type: res.taskDefinitionId, args: builder?.getArguments() }, projectFile, DotNetTarget.Test, StatusBarController.activeConfiguration);
3636
}
3737
public static getBuildTask(projectFile: string): vscode.Task {
3838
return DotNetTaskProvider.getTask({ type: res.taskDefinitionId }, projectFile, DotNetTarget.Build, StatusBarController.activeConfiguration);

src/VSCode/resources/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export const configIdDebuggerConsole = "debugger.console";
5858
export const configIdDebuggerSymbolSearchPaths = "debugger.symbolSearchPaths";
5959
export const configIdDebuggerSearchMicrosoftSymbolServer = "debugger.searchMicrosoftSymbolServer";
6060
export const configIdDebuggerAutomaticSourcelinkDownload = "debugger.automaticSourcelinkDownload";
61-
export const configIdDebuggerAutomaticLaunchSettingsLoad = "debugger.automaticLaunchSettingsLoad";
6261
export const configIdMSBuildNoRestore = "msbuild.noRestore";
6362
export const configIdMSBuildNoDependencies = "msbuild.noDependencies";
6463
export const configIdMSBuildAdditionalBuildArguments = "msbuild.additionalBuildArguments";
6564
export const configIdMSBuildAdditionalTestArguments = "msbuild.additionalTestArguments";
6665
export const configIdTestExplorerAutoRefreshTests = "testExplorer.autoRefreshTests";
67-
export const configIdTestExplorerSkipInitialPauseEvent = "testExplorer.skipInitialPauseEvent";
66+
export const configIdTestExplorerSkipInitialPauseEvent = "testExplorer.skipInitialPauseEvent";
67+
export const configIdTestExplorerPreLaunchTask = "testExplorer.preLaunchTask";

0 commit comments

Comments
 (0)