diff --git a/actions.go b/actions.go index 946a8c9..ab20a10 100644 --- a/actions.go +++ b/actions.go @@ -58,10 +58,13 @@ type WaitAction struct { // Execute performs the wait action. func (a WaitAction) Execute(ctx context.Context, wv *Webview) error { + timer := time.NewTimer(a.Duration) + defer timer.Stop() + select { case <-ctx.Done(): return ctx.Err() - case <-time.After(a.Duration): + case <-timer.C: return nil } } diff --git a/console.go b/console.go index 15de31a..780f2e3 100644 --- a/console.go +++ b/console.go @@ -60,6 +60,9 @@ func NewConsoleWatcher(wv *Webview) *ConsoleWatcher { // normalizeConsoleType converts CDP event types to package-level values. func normalizeConsoleType(raw string) string { normalized := strings.ToLower(core.Trim(core.Sprint(raw))) + if normalized == "warn" { + return "warning" + } return normalized } diff --git a/webview_test.go b/webview_test.go index 0989c28..13458f8 100644 --- a/webview_test.go +++ b/webview_test.go @@ -371,6 +371,41 @@ func TestFormatConsoleOutput_Good_Empty(t *testing.T) { } } +// TestNormalizeConsoleType_Good verifies CDP warning aliases are normalised. +func TestNormalizeConsoleType_Good(t *testing.T) { + if got := normalizeConsoleType("warn"); got != "warning" { + t.Fatalf("normalizeConsoleType(\"warn\") = %q, want %q", got, "warning") + } + if got := normalizeConsoleType("WARNING"); got != "warning" { + t.Fatalf("normalizeConsoleType(\"WARNING\") = %q, want %q", got, "warning") + } +} + +// TestWebviewHandleConsoleEvent_Good_NormalizesWarningType verifies CDP warn events are stored as warnings. +func TestWebviewHandleConsoleEvent_Good_NormalizesWarningType(t *testing.T) { + wv := &Webview{ + consoleLogs: make([]ConsoleMessage, 0), + consoleLimit: 10, + } + + wv.handleConsoleEvent(map[string]any{ + "type": "warn", + "args": []any{ + map[string]any{"value": "deprecated"}, + }, + }) + + if len(wv.consoleLogs) != 1 { + t.Fatalf("Expected one console message, got %d", len(wv.consoleLogs)) + } + if wv.consoleLogs[0].Type != "warning" { + t.Fatalf("Expected warning type, got %q", wv.consoleLogs[0].Type) + } + if wv.consoleLogs[0].Text != "deprecated" { + t.Fatalf("Expected text %q, got %q", "deprecated", wv.consoleLogs[0].Text) + } +} + // TestContainsString_Good verifies substring matching. func TestContainsString_Good(t *testing.T) { tests := []struct {