Skip to content

Commit 1b415ad

Browse files
committed
fix(debugger): seed initial route replay and stabilize conduit e2e
1 parent 707dbc3 commit 1b415ad

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

Picea.Abies.Browser/Runtime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ void NavigationExecutor(NavigationCommand command)
267267
{
268268
await JSHost.ImportAsync("AbiesDebugger", "../debugger.js");
269269
runtime.UseDebugger();
270+
runtime.SeedDebugger(initialUrl is not null ? new UrlChanged(initialUrl) : null);
270271
Interop.Debugger = runtime.Debugger;
271272
Interop.ApplyDebuggerSnapshot = runtime.TryApplyDebuggerSnapshot;
272273
if (runtime.Debugger is not null)

Picea.Abies.Conduit.Testing.E2E/ArticleTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ public async Task DeleteArticle_AsAuthor_ShouldNavigateToHome()
7373
await LoginViaUi(email, "password123");
7474

7575
await _page.NavigateInApp($"/article/{article.Slug}");
76-
await _page.WaitForSelectorAsync(".banner h1", new() { Timeout = 15000 });
76+
await Expect(_page).ToHaveURLAsync(new Regex($"/article/{Regex.Escape(article.Slug)}$"), new() { Timeout = 15000 });
77+
await Expect(_page.Locator(".article-page")).ToBeVisibleAsync(new() { Timeout = 15000 });
78+
await Expect(_page.Locator(".banner h1")).ToContainTextAsync(article.Title, new() { Timeout = 15000 });
7779

78-
await _page.Locator(".article-actions button.btn-outline-danger, .article-meta button.btn-outline-danger").First.ClickAsync();
80+
await _page.GetByRole(AriaRole.Button, new() { Name = "Delete Article" }).First.ClickAsync();
7981

8082
await _page.WaitForSelectorAsync(".home-page", new() { Timeout = 10000 });
8183
await _seeder.WaitForArticleDeletedAsync(article.Slug);

Picea.Abies.Conduit.Testing.E2E/CommentTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ public async Task Comments_ShouldRemainVisibleAfterReload()
206206
await _page.ReloadAsync();
207207
await _page.WaitForWasmReady();
208208

209-
await Expect(_page.Locator($"text={comment.Body}")).ToBeVisibleAsync(new() { Timeout = 10000 });
209+
var reloadedComment = _page
210+
.Locator(".card .card-block p")
211+
.Filter(new() { HasText = comment.Body })
212+
.First;
213+
214+
await Expect(reloadedComment).ToBeVisibleAsync(new() { Timeout = 10000 });
210215
}
211216

212217
[Test]

Picea.Abies.Conduit.Testing.E2E/Server/FeedServerTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,25 @@ public async Task ServerRuntime_ImportedTimelineReplay_ShouldApplySnapshots()
151151
await chooser.SetFilesAsync(exportedPath);
152152

153153
var timelineItems = _page.Locator("[data-sequence]");
154+
var firstTimelineItem = _page.Locator("[data-sequence='0']");
155+
var secondTimelineItem = _page.Locator("[data-sequence='1']");
154156
await Expect(timelineItems.First).ToBeVisibleAsync(new() { Timeout = 15000 });
155-
await Expect(timelineItems.Nth(1)).ToBeVisibleAsync(new() { Timeout = 15000 });
156-
157-
await timelineItems.First.ClickAsync();
157+
await Expect(secondTimelineItem).ToBeVisibleAsync(new() { Timeout = 15000 });
158+
159+
await _page.EvaluateAsync(
160+
"""
161+
() => document
162+
.querySelector("[data-sequence='0']")
163+
?.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
164+
""");
158165
await Expect(_page.Locator("h1")).ToContainTextAsync("Sign up", new() { Timeout = 10000 });
159166

160-
await timelineItems.Nth(1).ClickAsync();
167+
await _page.EvaluateAsync(
168+
"""
169+
() => document
170+
.querySelector("[data-sequence='1']")
171+
?.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }))
172+
""");
161173
await Expect(_page.Locator("h1")).ToContainTextAsync("Sign in", new() { Timeout = 10000 });
162174
}
163175

Picea.Abies.Server/Session.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void ServerApply(IReadOnlyList<Patch> patches)
211211
if (DebuggerConfiguration.Default.Enabled)
212212
{
213213
runtime.UseDebugger();
214+
runtime.SeedDebugger(initialUrl is not null ? new UrlChanged(initialUrl) : null);
214215
}
215216
#endif
216217

Picea.Abies/Runtime.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ public void UseDebugger(int capacity = 10000)
135135
_debuggerMachine = new DebuggerMachine(capacity);
136136
DebuggerRuntimeRegistry.CurrentDebugger = _debuggerMachine;
137137
}
138+
139+
/// <summary>
140+
/// Seeds the debugger with the runtime's current state and, optionally, a
141+
/// synthetic message that represents the state transition that already occurred
142+
/// before the debugger was attached.
143+
/// </summary>
144+
public void SeedDebugger(Message? message = null)
145+
{
146+
if (_debuggerMachine is null)
147+
{
148+
return;
149+
}
150+
151+
var modelSnapshot = GenerateModelSnapshot(_core.State);
152+
_debuggerMachine.CaptureInitialModel(modelSnapshot, _core.State);
153+
154+
if (message is not null)
155+
{
156+
_debuggerMachine.CaptureMessage(message, modelSnapshot, _core.State);
157+
}
158+
}
138159
#endif
139160

140161
private ValueTask<Result<Unit, PipelineError>> Observe(TModel state, Message _, Command __)

0 commit comments

Comments
 (0)