diff --git a/src/testCommands.ts b/src/testCommands.ts index e1414c6..66194a0 100644 --- a/src/testCommands.ts +++ b/src/testCommands.ts @@ -228,16 +228,25 @@ export class TestCommands implements Disposable { this.isRunning = false; } - private runBuildCommandForSpecificDirectory(testDirectoryPath: string): Promise { - return new Promise((resolve, reject) => { + private runBuildCommandForSpecificProject(testProjectPath: string): Promise { + return new Promise((resolve, reject) => { if (Utility.skipBuild) { Logger.Log(`User has passed --no-build, skipping build`); resolve(); } else { - Logger.Log(`Executing dotnet build in ${testDirectoryPath}`); + Logger.Log(`Executing dotnet build in ${testProjectPath}`); + + const isDirectory = fs.lstatSync(testProjectPath).isDirectory(); + const command = isDirectory + ? `dotnet build` + : `dotnet build ${testProjectPath}`; + + const testDirectoryPath = isDirectory + ? testProjectPath + : path.dirname(testProjectPath); - Executor.exec("dotnet build", (err: any, stdout: string) => { + Executor.exec(command, (err: any, stdout: string) => { if (err) { reject(new Error("Build command failed")); } @@ -247,7 +256,7 @@ export class TestCommands implements Disposable { }); } - private runTestCommandForSpecificDirectory(testDirectoryPath: string, testName: string, isSingleTest: boolean, index: number, debug?: boolean): Promise { + private runTestCommandForSpecificDirectory(testProjectPath: string, testName: string, isSingleTest: boolean, index: number, debug?: boolean): Promise { const trxTestName = index + ".trx"; @@ -255,6 +264,14 @@ export class TestCommands implements Disposable { const testResultFile = path.join(this.testResultsFolder, trxTestName); let command = `dotnet test${Utility.additionalArgumentsOption} --no-build --logger \"trx;LogFileName=${testResultFile}\"`; + const isDirectory = fs.lstatSync(testProjectPath).isDirectory(); + if (!isDirectory) + command += ` ${testProjectPath}`; + + const testDirectoryPath = isDirectory + ? testProjectPath + : path.dirname(testProjectPath); + if (testName && testName.length) { if (isSingleTest) { command = command + ` --filter "FullyQualifiedName=${testName.replace(/\(.*\)/g, "")}"`; @@ -263,7 +280,7 @@ export class TestCommands implements Disposable { } } - this.runBuildCommandForSpecificDirectory(testDirectoryPath) + this.runBuildCommandForSpecificProject(testProjectPath) .then(() => { Logger.Log(`Executing ${command} in ${testDirectoryPath}`);