Skip to content

Commit

Permalink
Fix running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deitry committed Dec 12, 2022
1 parent 0263f91 commit 576f15d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/testCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,25 @@ export class TestCommands implements Disposable {
this.isRunning = false;
}

private runBuildCommandForSpecificDirectory(testDirectoryPath: string): Promise<any> {
return new Promise<void>((resolve, reject) => {
private runBuildCommandForSpecificProject(testProjectPath: string): Promise<any> {
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"));
}
Expand All @@ -247,14 +256,22 @@ export class TestCommands implements Disposable {
});
}

private runTestCommandForSpecificDirectory(testDirectoryPath: string, testName: string, isSingleTest: boolean, index: number, debug?: boolean): Promise<any[]> {
private runTestCommandForSpecificDirectory(testProjectPath: string, testName: string, isSingleTest: boolean, index: number, debug?: boolean): Promise<any[]> {

const trxTestName = index + ".trx";

return new Promise((resolve, reject) => {
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, "")}"`;
Expand All @@ -263,7 +280,7 @@ export class TestCommands implements Disposable {
}
}

this.runBuildCommandForSpecificDirectory(testDirectoryPath)
this.runBuildCommandForSpecificProject(testProjectPath)
.then(() => {
Logger.Log(`Executing ${command} in ${testDirectoryPath}`);

Expand Down

0 comments on commit 576f15d

Please sign in to comment.