Skip to content

test: add third-party script error handling and duplicate prevention coverage - #888

Open
JemimahEkong wants to merge 1 commit into
Iris-IV:mainfrom
JemimahEkong:test/third-party-script-loading
Open

test: add third-party script error handling and duplicate prevention coverage#888
JemimahEkong wants to merge 1 commit into
Iris-IV:mainfrom
JemimahEkong:test/third-party-script-loading

Conversation

@JemimahEkong

Copy link
Copy Markdown
Contributor

PR: test(third-party): add script error handling and duplicate prevention coverage

This PR improves third-party script reliability by adding coverage for script load failures and preventing duplicate script injection scenarios.

Problem

The third-party script loading module lacked tests for two important edge cases:

  1. Handling failed third-party script loads through error events.
  2. Preventing duplicate script entries from creating multiple DOM script nodes.

What changed

src/lib/thirdParty.ts

  • Added optional onError?: () => void support to ThirdPartyScript so consumers can provide script-specific failure handlers.

  • Added duplicate script protection in getThirdPartyScripts():

    • Scripts with duplicate id values are filtered out.
    • Prevents accidental duplicate script injection at the configuration layer.
  • Exported handleScriptError(script) helper:

    • Safely invokes a configured error callback when a script fails to load.

src/components/ThirdPartyScripts.tsx

  • Updated script rendering logic to:

    • Extract onError from each script configuration.
    • Forward it to the Next.js <Script onError={...}> handler.

Test coverage

Added 2 new tests in:

src/__tests__/lib/thirdParty.test.ts

Covered scenarios:

Script load error handling

  • Confirms default scripts do not define error handlers.
  • Verifies custom onError callbacks are executed through handleScriptError.

Duplicate script prevention

  • Confirms returned scripts always contain unique IDs.
  • Ensures duplicate configurations cannot result in duplicate script injection.

Validation

  • ✅ All 12 tests passing

    • 10 existing tests
    • 2 new tests
  • ✅ No regressions introduced

Closes #844

…coverage

- Add onError callback to ThirdPartyScript interface
- Add dedup-by-id guard in getThirdPartyScripts()
- Wire onError prop in ThirdPartyScripts component
- Add handleScriptError() helper
- Add tests for error event handling and duplicate script IDs
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@JemimahEkong Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@sshdopey

Copy link
Copy Markdown
Contributor

Auto-review failed (API error). Leaving PR for human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Testing] Add unit tests for thirdParty.ts script-loading guard

2 participants