Skip to content

Conversation

@kotAPI
Copy link
Collaborator

@kotAPI kotAPI commented Sep 13, 2025

Summary by CodeRabbit

  • Tests
    • Streamlined test output by suppressing a specific repetitive warning from third-party components while preserving other warnings. Existing handling for “not wrapped in act(...)” remains unchanged. This reduces noise in CI and local runs, making failures easier to spot. No changes to public APIs or application behavior; adjustments are limited to the test harness.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 13, 2025

Walkthrough

Adds a console.warn filter in test setup to silence messages containing "asChild prop requires exactly one valid child element" while forwarding others. Retains existing console.error suppression for "not wrapped in act". Changes are confined to src/setupTests.ts and do not alter exported APIs.

Changes

Cohort / File(s) Summary of Changes
Test harness logging suppression
src/setupTests.ts
Wraps console.warn to ignore messages containing "asChild prop requires exactly one valid child element"; preserves original behavior for other warns. Keeps existing console.error filter for "not wrapped in act". No export/interface changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Jest as Test Runner
  participant Setup as setupTests.ts
  participant Console as console
  participant App as Test Subject

  Jest->>Setup: import/setup
  Setup->>Console: store original warn/error
  Setup->>Console: override console.warn and console.error

  App->>Console: console.warn("asChild prop requires exactly one valid child element")
  Console->>Console: check message contains substring
  alt matches filter
    Console-->>App: suppressed (no output)
  else forwards
    Console->>Console: call originalWarn(...args)
  end

  App->>Console: console.error("not wrapped in act(...)")
  Console->>Console: check message contains substring
  alt matches filter
    Console-->>App: suppressed (no output)
  else forwards
    Console->>Console: call originalError(...args)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A rabbit hushed the test bench’s din,
Nibbled warnings, slim and thin.
“asChild?”—shh, we’ll let that pass,
While real alarms still clink like glass.
In burrows deep, the logs stay clean—
Hop, hop, green checks on the screen! 🐇✅

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Silence Primitive asChild warning in tests" succinctly and accurately describes the primary change — adding suppression for the "asChild" console.warn in the test setup (src/setupTests.ts). It is concise, specific to the main behavior change, and avoids noisy or vague wording, so a teammate scanning PRs can quickly understand the intent. The title aligns with the PR objectives which state the change targets test logging behavior.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kotapi/silence-console.warn-during-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

Coverage

This report compares the PR with the base branch. “Δ” shows how the PR affects each metric.

Metric PR Δ
Statements 89.67% +0.00%
Branches 66.03% +0.00%
Functions 73.06% +0.00%
Lines 88.55% +0.00%

Coverage improved or stayed the same. Great job!

Run npm run coverage locally for detailed reports and target untested areas to raise these numbers.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/setupTests.ts (2)

35-44: Make the wrapper idempotent to avoid stacking across test files.

setupFilesAfterEnv can run per test file; guarding prevents multiple nested wrappers.

Apply:

-// Silence specific console warnings that are noisy in tests
-const originalWarn = console.warn;
-console.warn = (...args: unknown[]) => {
-    const firstArg = String(args[0]);
-    if (firstArg.includes('asChild prop requires exactly one valid child element')) {
-        return;
-    }
-    originalWarn(...(args as Parameters<typeof originalWarn>));
-};
+// Silence specific console warnings that are noisy in tests (idempotent)
+if (!(console.warn as any).__asChildSilenced) {
+  const originalWarn = console.warn.bind(console);
+  const wrapped = (...args: unknown[]) => {
+    const firstArg = String(args[0]);
+    if (firstArg.includes('asChild prop requires exactly one valid child element')) {
+      return;
+    }
+    originalWarn(...(args as Parameters<typeof originalWarn>));
+  };
+  (wrapped as any).__asChildSilenced = true;
+  console.warn = wrapped as any;
+}

38-41: Match across all args (case-insensitive) to reduce false negatives.

Some libraries pass template strings + args; scanning all args makes the filter more robust.

Apply:

-    const firstArg = String(args[0]);
-    if (firstArg.includes('asChild prop requires exactly one valid child element')) {
+    const haystack = args.map((a) => String(a)).join(' ').toLowerCase();
+    if (haystack.includes('aschild prop requires exactly one valid child element')) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b997c83 and 3d8a630.

📒 Files selected for processing (1)
  • src/setupTests.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build
  • GitHub Check: coverage
🔇 Additional comments (1)
src/setupTests.ts (1)

35-44: Targeted suppression looks good.

Only the specific Primitive asChild warning is silenced; other warnings are forwarded. Matches existing console.error pattern and keeps test output clean.

@kotAPI kotAPI merged commit 33bb0e0 into main Sep 13, 2025
11 checks passed
@kotAPI kotAPI deleted the kotapi/silence-console.warn-during-tests branch September 13, 2025 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants