Skip to content

fix: prefer globalThis over global in Jest setup (Sonar S7764)#3070

Merged
arkid15r merged 6 commits intoOWASP:mainfrom
anukalp2804:fix-globalthis-sonar-s7764
Dec 29, 2025
Merged

fix: prefer globalThis over global in Jest setup (Sonar S7764)#3070
arkid15r merged 6 commits intoOWASP:mainfrom
anukalp2804:fix-globalthis-sonar-s7764

Conversation

@anukalp2804
Copy link
Contributor

Proposed change

Replaced usage of global with globalThis in frontend/jest.setup.ts
to comply with SonarCloud rule typescript:S7764. This ensures consistent
behavior across environments (Node.js, browser, workers) and improves
maintainability.

Resolves #3069

Checklist

  • I read and followed the contributing guidelines
  • I ran frontend unit tests locally and all tests passed
  • I used AI for code, documentation, or tests in this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

Summary by CodeRabbit

  • Chores
    • Removed internal test setup configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Removed conditional structuredClone polyfill assignment from frontend/jest.setup.ts that relied on the global object. The polyfill block is deleted, with structuredClone handling delegated to other imports.

Changes

Cohort / File(s) Summary
Jest Setup Polyfill Removal
frontend/jest.setup.ts
Removed conditional global.structuredClone polyfill assignment block. No replacement or new polyfill logic introduced.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

frontend-tests

Suggested reviewers

  • kasya

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR fails to meet the primary objective from issue #3069: the summary shows the polyfill block was removed rather than replaced with globalThis, leaving no explicit globalThis implementation. Verify the actual implementation contains globalThis.structuredClone assignment instead of just removing the polyfill block. Update the code to replace global with globalThis as specified in issue #3069.
Out of Scope Changes check ❓ Inconclusive The only change is removal of the polyfill block in frontend/jest.setup.ts, which is within scope. However, the removal without replacement appears to deviate from the intended fix of substituting global with globalThis. Clarify whether the polyfill removal was intentional or if the globalThis replacement was incomplete. Ensure the final implementation aligns with issue #3069 requirements.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing global with globalThis in Jest setup to comply with SonarCloud rule S7764.
Description check ✅ Passed The description clearly relates to the changeset, explaining the switch from global to globalThis and its alignment with SonarCloud rule typescript:S7764.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ebc934 and 949e91a.

📒 Files selected for processing (1)
  • frontend/jest.setup.ts
💤 Files with no reviewable changes (1)
  • frontend/jest.setup.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@anukalp2804
Copy link
Contributor Author

This PR addresses SonarCloud rule typescript:S7764 and ensures environment-agnostic behavior using globalThis.
All local tests have passed successfully.
Please let me know if any additional adjustments are required.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 29, 2025
@Shofikul-Isl4m
Copy link
Contributor

screenshot-2025-12-29_09-30-58 Based on my past contribution experience, you have to address the SonarCloud issues.

@anukalp2804
Copy link
Contributor Author

screenshot-2025-12-29_09-30-58 Based on my past contribution experience, you have to address the SonarCloud issues.

Addressed the SonarCloud issue by explicitly documenting the intentional
structuredClone polyfill and marking the fallback with NOSONAR.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 29, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 29, 2025
@sonarqubecloud
Copy link

@arkid15r arkid15r enabled auto-merge December 29, 2025 19:04
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

I removed the redundant fallback polyfill. The file already imports core-js/actual/structured-clone at the top, which provides a proper structuredClone polyfill, so the JSON.parse(JSON.stringify(...)) fallback was unnecessary and triggered the SonarQube rule.

@arkid15r arkid15r added this pull request to the merge queue Dec 29, 2025
Merged via the queue into OWASP:main with commit 0acf5df Dec 29, 2025
25 checks passed
Mr-Rahul-Paul pushed a commit to Mr-Rahul-Paul/Nest that referenced this pull request Jan 2, 2026
…#3070)

* refactor: remove redundant exception handling reported by SonarCloud

* fix: prefer globalThis over global in Jest setup (Sonar S7764)

* chore: suppress intentional structuredClone polyfill fallback (NOSONAR)

* chore: suppress Sonar warning for intentional structuredClone polyfill

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
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.

Replace usage of global with globalThis in Jest setup (Sonar S7764)

3 participants