Skip to content
Merged
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
43 changes: 43 additions & 0 deletions eng/testing/select-affected-tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ public static async Task<int> MainAsync(string[] args)
continue;
}

if (TryGetExampleTests(filePath, projectPaths, nodeToTests, out var exampleName, out var impactedExampleTests))
{
selected.UnionWith(impactedExampleTests);
reasons.Add($"Selected {impactedExampleTests.Count} tests because {filePath} belongs to example {exampleName}.");
continue;
}

if (filePath.StartsWith("src/", StringComparison.Ordinal) ||
filePath.StartsWith("tests/", StringComparison.Ordinal) ||
filePath.StartsWith("examples/", StringComparison.Ordinal) ||
Expand Down Expand Up @@ -571,6 +578,42 @@ private static bool TryGetTypeScriptAppHostTests(
return false;
}

private static bool TryGetExampleTests(
string filePath,
List<string> projectPaths,
Dictionary<string, HashSet<string>> nodeToTests,
out string exampleName,
out HashSet<string> tests)
{
tests = [];
exampleName = string.Empty;

if (!filePath.StartsWith("examples/", StringComparison.Ordinal))
{
return false;
}

var segments = filePath.Split('/', StringSplitOptions.RemoveEmptyEntries);
if (segments.Length < 2)
{
return false;
}

exampleName = segments[1];
var examplePrefix = $"examples/{exampleName}/";
var exampleProjects = projectPaths.Where(projectPath => projectPath.StartsWith(examplePrefix, StringComparison.Ordinal));

foreach (var projectPath in exampleProjects)
{
if (nodeToTests.TryGetValue(projectPath, out var impacted))
{
tests.UnionWith(impacted);
}
}

return tests.Count > 0;
}

private static Dictionary<string, string> ParseStringConstants(string contents)
{
var constants = new Dictionary<string, string>(StringComparer.Ordinal);
Expand Down
Loading