Skip to content

Commit

Permalink
Support testing specific projects
Browse files Browse the repository at this point in the history
  • Loading branch information
deitry committed Dec 12, 2022
1 parent 2be5abe commit a891b44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
21 changes: 8 additions & 13 deletions src/testDirectories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,23 @@ export class TestDirectories {

}
function evaluateTestDirectories(testDirectories: string[]): string[] {
const directories = [];
const directoriesSet = new Set<string>();
const projectPaths = [];
const projectPathsSet = new Set<string>();

for (let testProjectFullPath of testDirectories) {
Logger.Log(`Evaluating match ${testProjectFullPath}`);

if (!fs.existsSync(testProjectFullPath)) {
Logger.LogWarning(`Path ${testProjectFullPath} is not valid`);
} else {

if (fs.lstatSync(testProjectFullPath).isFile()) {
testProjectFullPath = path.dirname(testProjectFullPath);
}

if (glob.sync(`${testProjectFullPath}/+(*.csproj|*.sln|*.fsproj)`).length < 1) {
Logger.LogWarning(`Skipping path ${testProjectFullPath} since it does not contain something we can build (.sln, .csproj, .fsproj)`);
} else if (!directoriesSet.has(testProjectFullPath)) {
if (fs.lstatSync(testProjectFullPath).isDirectory() && glob.sync(`${testProjectFullPath}/+(*.csproj|*.sln|*.slnf|*.fsproj)`).length < 1) {
Logger.LogWarning(`Skipping path ${testProjectFullPath} since it does not contain something we can build (.sln, .slnf, .csproj, .fsproj)`);
} else if (!projectPathsSet.has(testProjectFullPath)) {
Logger.Log(`Adding directory ${testProjectFullPath}`);
directories.push(testProjectFullPath);
directoriesSet.add(testProjectFullPath);
projectPaths.push(testProjectFullPath);
projectPathsSet.add(testProjectFullPath);
}
}
}
return directories;
return projectPaths;
}
18 changes: 15 additions & 3 deletions src/testDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ export function discoverTests(testDirectoryPath: string, dotnetTestOptions: stri
});
}

function executeDotnetTest(testDirectoryPath: string, dotnetTestOptions: string): Promise<string> {
function executeDotnetTest(testProjectPath: string, dotnetTestOptions: string): Promise<string> {
return new Promise((resolve, reject) => {
const command = `dotnet test -t -v=q${dotnetTestOptions}`;
const isDirectory = fs.lstatSync(testProjectPath).isDirectory();
const command = isDirectory
? `dotnet test -t -v=q${dotnetTestOptions}`
: `dotnet test -t -v=q${dotnetTestOptions} ${testProjectPath}`;

const testDirectoryPath = isDirectory
? testProjectPath
: path.dirname(testProjectPath);

Logger.Log(`Executing ${command} in ${testDirectoryPath}`);

Expand Down Expand Up @@ -169,11 +176,16 @@ function cleanTestOutput(testOutputFilePath: string) {
fs.rmdirSync(path.dirname(testOutputFilePath));
}

function executeDotnetVstest(assemblyPaths: string[], listTestsTargetPath: string, testDirectoryPath: string): Promise<string> {
function executeDotnetVstest(assemblyPaths: string[], listTestsTargetPath: string, testProjectPath: string): Promise<string> {
return new Promise((resolve, reject) => {
const testAssembliesParam = assemblyPaths.map((f) => `"${f}"`).join(" ");
const command = `dotnet vstest ${testAssembliesParam} /ListFullyQualifiedTests /ListTestsTargetPath:"${listTestsTargetPath}"`;

const isDirectory = fs.lstatSync(testProjectPath).isDirectory();
const testDirectoryPath = isDirectory
? testProjectPath
: path.dirname(testProjectPath);

Logger.Log(`Executing ${command} in ${testDirectoryPath}`);

Executor.exec(
Expand Down

0 comments on commit a891b44

Please sign in to comment.