Skip to content

Commit 7592fdf

Browse files
committed
Refactor end-to-end test reporting and improve self-contained system handling
1 parent 68a50f2 commit 7592fdf

File tree

1 file changed

+51
-33
lines changed

1 file changed

+51
-33
lines changed

developer-cli/Commands/End2EndCommand.cs

Lines changed: 51 additions & 33 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 SCS is provided, run tests for all available systems
73-
var systemsToTest = selfContainedSystem != null ? [selfContainedSystem] : availableSystems;
72+
// If no specific self-contained system is provided, run tests for all available self-contained systems
73+
var selfContainedSystemsToTest = selfContainedSystem != null ? [selfContainedSystem] : availableSystems;
7474

7575
// Validate self-contained system if provided
7676
if (selfContainedSystem is not null && !availableSystems.Contains(selfContainedSystem))
@@ -91,16 +91,18 @@ private static void Execute(
9191

9292
var stopwatch = Stopwatch.StartNew();
9393
var overallSuccess = true;
94+
var failedSelfContainedSystems = new List<string>();
9495

95-
foreach (var system in systemsToTest)
96+
foreach (var currentSelfContainedSystem in selfContainedSystemsToTest)
9697
{
97-
var systemSuccess = RunTestsForSystem(system, testPatterns, browser, debug, grep, headed, includeSlow,
98-
lastFailed, onlyChanged, quiet, repeatEach, retries, showReport, slowMotion, smoke, stopOnFirstFailure, ui
98+
var selfContainedSystemSuccess = RunTestsForSystem(currentSelfContainedSystem, testPatterns, browser, debug, grep, headed, includeSlow, lastFailed,
99+
onlyChanged, quiet, repeatEach, retries, showReport, slowMotion, smoke, stopOnFirstFailure, ui
99100
);
100101

101-
if (!systemSuccess)
102+
if (!selfContainedSystemSuccess)
102103
{
103104
overallSuccess = false;
105+
failedSelfContainedSystems.Add(currentSelfContainedSystem);
104106
}
105107
}
106108

@@ -111,11 +113,29 @@ private static void Execute(
111113
: $"[red]Some tests failed in {stopwatch.Elapsed.TotalSeconds:F1} seconds[/]"
112114
);
113115

116+
if (!quiet)
117+
{
118+
if (showReport)
119+
{
120+
foreach (var currentSelfContainedSystem in selfContainedSystemsToTest)
121+
{
122+
OpenHtmlReport(currentSelfContainedSystem);
123+
}
124+
}
125+
else if (!overallSuccess)
126+
{
127+
foreach (var currentSelfContainedSystem in failedSelfContainedSystems)
128+
{
129+
OpenHtmlReport(currentSelfContainedSystem);
130+
}
131+
}
132+
}
133+
114134
if (!overallSuccess) Environment.Exit(1);
115135
}
116136

117137
private static bool RunTestsForSystem(
118-
string system,
138+
string selfContainedSystem,
119139
string[] testPatterns,
120140
string browser,
121141
bool debug,
@@ -133,25 +153,25 @@ private static bool RunTestsForSystem(
133153
bool stopOnFirstFailure,
134154
bool ui)
135155
{
136-
var systemPath = Path.Combine(Configuration.ApplicationFolder, system, "WebApp");
156+
var systemPath = Path.Combine(Configuration.ApplicationFolder, selfContainedSystem, "WebApp");
137157
var e2eTestsPath = Path.Combine(systemPath, "e2e-tests");
138158

139159
if (!Directory.Exists(e2eTestsPath))
140160
{
141-
AnsiConsole.MarkupLine($"[yellow]No e2e tests found for {system}, skipping...[/]");
161+
AnsiConsole.MarkupLine($"[yellow]No e2e tests found for {selfContainedSystem}. Skipping...[/]");
142162
return true;
143163
}
144164

145-
AnsiConsole.MarkupLine($"[blue]Running tests for {system}...[/]");
165+
AnsiConsole.MarkupLine($"[blue]Running tests for {selfContainedSystem}...[/]");
146166

147167
// Clean up report directory if we're going to show it
148168
if (showReport)
149169
{
150-
var reportPath = Path.Combine(e2eTestsPath, "playwright-report");
151-
if (Directory.Exists(reportPath))
170+
var reportDirectory = Path.Combine(e2eTestsPath, "playwright-report");
171+
if (Directory.Exists(reportDirectory))
152172
{
153173
AnsiConsole.MarkupLine("[blue]Cleaning up previous test report...[/]");
154-
Directory.Delete(reportPath, true);
174+
Directory.Delete(reportDirectory, true);
155175
}
156176
}
157177

@@ -172,7 +192,7 @@ private static bool RunTestsForSystem(
172192
UseShellExecute = false
173193
};
174194

175-
AnsiConsole.MarkupLine($"[cyan]Running command in {system}: npx playwright test --config=./e2e-tests/playwright.config.ts {playwrightArgs}[/]");
195+
AnsiConsole.MarkupLine($"[cyan]Running command in {selfContainedSystem}: npx playwright test --config=./e2e-tests/playwright.config.ts {playwrightArgs}[/]");
176196

177197
processStartInfo.EnvironmentVariables["PUBLIC_URL"] = BaseUrl;
178198

@@ -187,17 +207,14 @@ private static bool RunTestsForSystem(
187207
try
188208
{
189209
ProcessHelper.StartProcess(processStartInfo, throwOnError: true);
190-
AnsiConsole.MarkupLine($"[green]Tests for {system} completed successfully[/]");
210+
AnsiConsole.MarkupLine(testsFailed
211+
? $"[red]Tests for {selfContainedSystem} failed[/]"
212+
: $"[green]Tests for {selfContainedSystem} completed successfully[/]");
191213
}
192214
catch (Exception)
193215
{
194216
testsFailed = true;
195-
AnsiConsole.MarkupLine($"[red]Tests for {system} failed[/]");
196-
}
197-
198-
if (!quiet && (showReport || testsFailed))
199-
{
200-
OpenHtmlReport(e2eTestsPath, system);
217+
AnsiConsole.MarkupLine($"[red]Tests for {selfContainedSystem} failed[/]");
201218
}
202219

203220
return !testsFailed;
@@ -230,28 +247,28 @@ private static void CheckWebsiteAccessibility()
230247

231248
private static string[] GetAvailableSelfContainedSystems()
232249
{
233-
var applicationPath = Configuration.ApplicationFolder;
234-
var systems = new List<string>();
250+
var selfContainedSystems = new List<string>();
235251

236252
// Look for directories that contain WebApp/e2e-tests
237-
foreach (var directory in Directory.GetDirectories(applicationPath))
253+
foreach (var directory in Directory.GetDirectories(Configuration.ApplicationFolder))
238254
{
239-
var dirName = Path.GetFileName(directory);
255+
var directoryName = Path.GetFileName(directory);
240256

241-
// Skip known non-SCS directories
242-
if (dirName is "AppHost" or "AppGateway" or "shared-kernel" or "shared-webapp")
257+
// Skip directories that are not self-contained systems
258+
if (directoryName.StartsWith('.') || directoryName == "AppGateway" || directoryName == "AppHost" ||
259+
directoryName == "shared-kernel" || directoryName == "shared-webapp")
243260
{
244261
continue;
245262
}
246263

247264
var e2eTestsPath = Path.Combine(directory, "WebApp", "e2e-tests");
248265
if (Directory.Exists(e2eTestsPath))
249266
{
250-
systems.Add(dirName);
267+
selfContainedSystems.Add(directoryName);
251268
}
252269
}
253270

254-
return systems.ToArray();
271+
return selfContainedSystems.ToArray();
255272
}
256273

257274
private static string BuildPlaywrightArgs(
@@ -312,17 +329,18 @@ private static string BuildPlaywrightArgs(
312329
return string.Join(" ", args);
313330
}
314331

315-
private static void OpenHtmlReport(string e2eTestsPath, string system)
332+
private static void OpenHtmlReport(string selfContainedSystem)
316333
{
317-
var reportPath = Path.Combine(e2eTestsPath, "playwright-report", "index.html");
334+
var reportPath = Path.Combine(Configuration.ApplicationFolder, selfContainedSystem, "WebApp", "playwright-report", "index.html");
335+
318336
if (File.Exists(reportPath))
319337
{
320-
AnsiConsole.MarkupLine($"[green]Opening test report for {system}...[/]");
338+
AnsiConsole.MarkupLine($"[green]Opening test report for '{selfContainedSystem}'...[/]");
321339
ProcessHelper.OpenBrowser(reportPath);
322340
}
323341
else
324342
{
325-
AnsiConsole.MarkupLine($"[yellow]No test report found for {system} at playwright-report/index.html[/]");
343+
AnsiConsole.MarkupLine($"[yellow]No test report found for '{selfContainedSystem}' at '{reportPath}'[/]");
326344
}
327345
}
328346
}

0 commit comments

Comments
 (0)