Skip to content

Commit c429074

Browse files
committed
Detect self-contained system for e2e CLI command execution
1 parent 7592fdf commit c429074

File tree

1 file changed

+100
-2
lines changed

1 file changed

+100
-2
lines changed

developer-cli/Commands/End2EndCommand.cs

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ private static void Execute(
6969
Environment.Exit(1);
7070
}
7171

72-
// If no specific self-contained system is provided, run tests for all available self-contained systems
73-
var selfContainedSystemsToTest = selfContainedSystem != null ? [selfContainedSystem] : availableSystems;
72+
// Determine which self-contained systems to test based on the provided patterns or grep
73+
var selfContainedSystemsToTest = DetermineSystemsToTest(selfContainedSystem, availableSystems, testPatterns, grep);
7474

7575
// Validate self-contained system if provided
7676
if (selfContainedSystem is not null && !availableSystems.Contains(selfContainedSystem))
@@ -103,6 +103,12 @@ private static void Execute(
103103
{
104104
overallSuccess = false;
105105
failedSelfContainedSystems.Add(currentSelfContainedSystem);
106+
107+
// If stop on first failure is enabled, exit the loop after the first failure
108+
if (stopOnFirstFailure)
109+
{
110+
break;
111+
}
106112
}
107113
}
108114

@@ -245,6 +251,98 @@ private static void CheckWebsiteAccessibility()
245251
Environment.Exit(1);
246252
}
247253

254+
private static string[] DetermineSystemsToTest(string? specifiedSelfContainedSystem, string[] availableSystems, string[] testPatterns, string? grep)
255+
{
256+
// If a specific self-contained system is provided, use only that one
257+
if (specifiedSelfContainedSystem != null)
258+
{
259+
return [specifiedSelfContainedSystem];
260+
}
261+
262+
// If no patterns or grep are provided, run tests for all systems
263+
if ((testPatterns.Length == 0 || testPatterns[0] == "*") && string.IsNullOrEmpty(grep))
264+
{
265+
return availableSystems;
266+
}
267+
268+
// Check if test patterns match specific files in any self-contained system
269+
var matchingSystems = new HashSet<string>();
270+
271+
foreach (var pattern in testPatterns)
272+
{
273+
// Skip wildcard patterns as they don't help us narrow down the systems
274+
if (pattern == "*" || (pattern.Contains("*") && !pattern.EndsWith(".spec.ts")))
275+
{
276+
continue;
277+
}
278+
279+
if (pattern is null)
280+
{
281+
continue;
282+
}
283+
284+
// Normalize the pattern to handle both file names and paths
285+
var normalizedPattern = pattern.EndsWith(".spec.ts") ? pattern : $"{pattern}.spec.ts";
286+
normalizedPattern = Path.GetFileName(normalizedPattern);
287+
288+
foreach (var system in availableSystems)
289+
{
290+
var e2eTestsPath = Path.Combine(Configuration.ApplicationFolder, system, "WebApp", "e2e-tests");
291+
if (!Directory.Exists(e2eTestsPath))
292+
{
293+
continue;
294+
}
295+
296+
var testFiles = Directory.GetFiles(e2eTestsPath, "*.spec.ts", SearchOption.AllDirectories)
297+
.Select(Path.GetFileName)
298+
.ToArray();
299+
300+
if (testFiles.Any(file => file?.Equals(normalizedPattern, StringComparison.OrdinalIgnoreCase) == true))
301+
{
302+
matchingSystems.Add(system);
303+
}
304+
}
305+
}
306+
307+
// If we found matching systems based on file patterns, return those
308+
if (matchingSystems.Count > 0)
309+
{
310+
return matchingSystems.ToArray();
311+
}
312+
313+
// If grep is provided, try to find matching test content
314+
if (!string.IsNullOrEmpty(grep))
315+
{
316+
foreach (var system in availableSystems)
317+
{
318+
var e2eTestsPath = Path.Combine(Configuration.ApplicationFolder, system, "WebApp", "e2e-tests");
319+
if (!Directory.Exists(e2eTestsPath))
320+
{
321+
continue;
322+
}
323+
324+
var testFiles = Directory.GetFiles(e2eTestsPath, "*.spec.ts", SearchOption.AllDirectories);
325+
foreach (var testFile in testFiles)
326+
{
327+
var fileContent = File.ReadAllText(testFile);
328+
if (fileContent.Contains(grep, StringComparison.OrdinalIgnoreCase))
329+
{
330+
matchingSystems.Add(system);
331+
break; // Found a match in this system, no need to check other files
332+
}
333+
}
334+
}
335+
336+
if (matchingSystems.Count > 0)
337+
{
338+
return matchingSystems.ToArray();
339+
}
340+
}
341+
342+
// If we couldn't determine specific systems, run tests for all systems
343+
return availableSystems;
344+
}
345+
248346
private static string[] GetAvailableSelfContainedSystems()
249347
{
250348
var selfContainedSystems = new List<string>();

0 commit comments

Comments
 (0)