Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(monorepo): update MSW and othr dependencies to latest #1629

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

bardisg
Copy link
Contributor

@bardisg bardisg commented Feb 27, 2024

PR Description

update MSW and othr dependencies to latest

Linear task (optional)

Linear task link

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • Refactor
    • Updated test environment settings for better compatibility and extended functionality.
    • Streamlined test utilities and mocks for improved testing efficiency.
    • Enhanced HTTP request handling in testing fixtures and services for more precise response simulation.
  • Tests
    • Adjusted script loading in tests to accommodate file extension changes.
    • Updated import paths and request handling logic in service worker tests.
    • Refined server interaction tests for clearer descriptions and response handling.
  • Chores
    • Made internal adjustments to improve development tools and output handling.

Copy link
Contributor

coderabbitai bot commented Feb 27, 2024

Walkthrough

This update primarily focuses on enhancing testing environments and server response handling across various components of a JavaScript analytics framework. It introduces a shift from using REST to HTTP for better control over responses, streamlines polyfills, and extends the JSDOM environment for improved testing compatibility. Additionally, it revises the handling of JavaScript file loading and updates server mock setups, ensuring a more robust and efficient testing strategy.

Changes

Files Change Summary
jest.preset.js Updated testEnvironment to a custom extended JSDOM environment.
jest/jest.polyfills.js Streamlined by removing unused imports and adjusting global mocks.
jest/jsdom-extended.js Created for extending JSDOM environment.
.../__fixtures__/msw.handlers.ts/js Updated to use http and HttpResponse for handling HTTP requests.
.../__tests__/.../ExternalSrcLoader.test.ts, .../ConfigManager.test.ts Updated script loading and response handling with .js extension and HttpResponse.
.../__fixtures__/msw.server.ts Introduced server setup using msw/node for handling HTTP POST requests.
.../__tests__/Analytics.test.ts Updated import paths and request data handling within event listeners.
patches/nx+18.0.5.patch Modified classes in static-run-many-terminal-output-life-cycle.js and output.js.

"In the realm of code, where tests and mocks reside,
A rabbit hopped, with changes wide.
From REST to HTTP, it took its stride,
🌟 Enhancing flows, with each file slide.
'Tis a journey of tweaks, far and wide,
In jest and msw, our trust we confide."
🐰✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@bardisg
Copy link
Contributor Author

bardisg commented Feb 27, 2024

@coderabbitai review

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4e1d279 and df8efe9.
Files ignored due to path filters (14)
  • package-lock.json is excluded by: !**/*.json
  • package.json is excluded by: !**/*.json
  • packages/analytics-js-common/package.json is excluded by: !**/*.json
  • packages/analytics-js-common/tsconfig.spec.json is excluded by: !**/*.json
  • packages/analytics-js-integrations/tsconfig.spec.json is excluded by: !**/*.json
  • packages/analytics-js-plugins/package.json is excluded by: !**/*.json
  • packages/analytics-js-plugins/tsconfig.spec.json is excluded by: !**/*.json
  • packages/analytics-js-service-worker/package.json is excluded by: !**/*.json
  • packages/analytics-js-service-worker/tsconfig.spec.json is excluded by: !**/*.json
  • packages/analytics-js/tsconfig.spec.json is excluded by: !**/*.json
  • packages/analytics-v1.1/package.json is excluded by: !**/*.json
  • packages/analytics-v1.1/tsconfig.spec.json is excluded by: !**/*.json
  • packages/loading-scripts/tsconfig.spec.json is excluded by: !**/*.json
  • packages/sanity-suite/__fixtures__/sourceConfig1.json is excluded by: !**/*.json
Files selected for processing (13)
  • jest.preset.js (1 hunks)
  • jest/jest.polyfills.js (2 hunks)
  • jest/jsdom-extended.js (1 hunks)
  • packages/analytics-js-common/fixtures/msw.handlers.ts (1 hunks)
  • packages/analytics-js-common/tests/services/ExternalSrcLoader/ExternalSrcLoader.test.ts (6 hunks)
  • packages/analytics-js-plugins/fixtures/msw.handlers.js (2 hunks)
  • packages/analytics-js-service-worker/fixtures/msw.server.ts (1 hunks)
  • packages/analytics-js-service-worker/tests/Analytics.test.ts (3 hunks)
  • packages/analytics-js/fixtures/msw.handlers.ts (1 hunks)
  • packages/analytics-js/tests/components/configManager/ConfigManager.test.ts (2 hunks)
  • packages/analytics-v1.1/fixtures/msw.handlers.js (2 hunks)
  • packages/analytics-v1.1/tests/transformationHandler.test.js (5 hunks)
  • patches/nx+18.0.5.patch (2 hunks)
Files skipped from review due to trivial changes (1)
  • jest/jest.polyfills.js
Additional comments: 19
packages/analytics-js-service-worker/__fixtures__/msw.server.ts (2)
  • 1-3: The import statements for setupServer from msw/node, and http, HttpResponse from msw are correctly updated to reflect the new usage patterns introduced by the MSW library update. This aligns with the PR's objective to update dependencies and improve HTTP request handling in tests.
  • 5-11: The setup of the MSW server using http.post to handle POST requests to ${dummyDataplaneHost}/v1/batch with a 200 status response is correctly implemented. This change from the previous rest handlers to http handlers is in line with the MSW update and enhances the control over server responses. The use of HttpResponse to specify the response status is appropriate and follows best practices for testing HTTP interactions.
jest/jsdom-extended.js (1)
  • 1-26: The extension of JSDOMEnvironment to include polyfills for ReadableStream, TextDecoder, TextEncoder, Blob, File, Headers, FormData, Request, Response, and fetch is correctly implemented. This ensures compatibility with MSW v2 by providing the necessary global objects that might be used by MSW or tests. The inclusion of structuredClone is also a good practice, as it's a modern API for deep cloning objects. This setup is essential for tests that rely on these APIs being available in the JSDOM environment.
packages/analytics-js-plugins/__fixtures__/msw.handlers.js (2)
  • 1-1: The import statement correctly updates to use http and HttpResponse from msw, aligning with the PR's objective to leverage the latest MSW functionalities for handling HTTP requests in a more controlled manner.
  • 10-41: The update to use http.post for defining request handlers and the use of HttpResponse for specifying responses is correctly implemented across various scenarios (success, partialSuccess, invalidResponse, badRequest, accessDenied, serverDown). This change enhances the flexibility and control over the mock server's responses, allowing for more detailed specification of response content and headers. It's also consistent with the PR's goal of updating to the latest MSW version and improving HTTP request handling in tests.
packages/analytics-v1.1/__fixtures__/msw.handlers.js (2)
  • 1-1: The import statement correctly updates to use http and HttpResponse from msw, aligning with the PR's objective to leverage the latest MSW functionalities for handling HTTP requests in a more controlled manner.
  • 10-47: The update to use http.post for defining request handlers and the use of HttpResponse for specifying responses is correctly implemented across various scenarios (success, partialSuccess, invalidResponse, badRequest, accessDenied, serverDown). This change enhances the flexibility and control over the mock server's responses, allowing for more detailed specification of response content and headers. It's also consistent with the PR's goal of updating to the latest MSW version and improving HTTP request handling in tests.
packages/analytics-js-common/__tests__/services/ExternalSrcLoader/ExternalSrcLoader.test.ts (10)
  • 42-42: Appending .js to the URL ensures that scripts are loaded correctly with the updated file extensions. This change is consistent with the PR's objectives and appears to be correctly applied here.
  • 47-47: The URL for loading the JavaScript file correctly includes the .js extension, aligning with the changes made elsewhere in this file. This consistency is crucial for the correct loading of scripts.
  • 81-81: Again, the .js extension is correctly appended to the URL, ensuring consistency across the test cases. This change is necessary for the correct loading of scripts with the updated file extensions.
  • 93-96: The creation of a script element with a URL that includes the .js extension is consistent with the PR's objectives. This ensures that the script is loaded correctly with the updated file extensions.
  • 100-100: The assertion checks the script's src attribute for the correct URL, including the .js extension. This is a good practice to ensure that the script is loaded as expected.
  • 110-113: Creating a script element with the .js extension in the URL is consistent with the changes made throughout this file. This consistency is important for the correct loading of scripts.
  • 116-116: Inserting a script with the .js extension in the URL ensures that the script is loaded correctly. This change aligns with the PR's objectives and is applied consistently.
  • 129-129: The script element's src attribute correctly includes the .js extension, ensuring that the script is loaded as expected. This consistency with the PR's objectives is crucial.
  • 154-154: The assertion checks for the correct src attribute, including the .js extension. This ensures that the script is loaded correctly, aligning with the PR's objectives.
  • 161-161: Loading a JavaScript file with the URL correctly including the .js extension is consistent with the changes made elsewhere in this file. This consistency is crucial for the correct loading of scripts.
packages/analytics-js/__tests__/components/configManager/ConfigManager.test.ts (2)
  • 2-2: The import of http and HttpResponse from msw is correctly added to replace the previous rest usage. This change aligns with the PR's objectives to enhance HTTP request handling in tests.
  • 139-146: The replacement of rest with http for making a GET request and the use of HttpResponse for specifying the response is correctly implemented. This change enhances the control over server responses by allowing for more detailed specification of response content and headers, aligning with the PR's objectives.

Copy link

codecov bot commented Feb 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.32%. Comparing base (4e1d279) to head (df8efe9).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1629      +/-   ##
===========================================
- Coverage    54.70%   52.32%   -2.39%     
===========================================
  Files          581      581              
  Lines        17740    16592    -1148     
  Branches      3236     3239       +3     
===========================================
- Hits          9704     8681    -1023     
+ Misses        6623     6436     -187     
- Partials      1413     1475      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Common Code - No bundling 15.76 KB 15.76 KB (0%) 16.5 KB
Remote Module Federation Mapping - CDN 330 B 330 B (0%) 512 B
Remote Module Federated Plugins - CDN 5.71 KB 5.71 KB (0%) 6 KB
Core ESM - NPM 7.64 KB 7.64 KB (0%) 8 KB
Core CJS - NPM 22.4 KB 22.4 KB (0%) 23 KB
Core - NPM 22.56 KB 22.56 KB (0%) 23 KB
Core Legacy - CDN 42.77 KB 42.77 KB (0%) 44 KB
Core - CDN 22.67 KB 22.67 KB (0%) 23 KB
Core (legacy build) - CDN - v1.1 31.37 KB 31.37 KB (0%) 32 KB
Core - NPM - v1.1 31.5 KB 31.5 KB (0%) 32 KB
Service Worker Module 22.64 KB 22.64 KB (0%) 24 KB
All Integrations (legacy build) - CDN 97.72 KB 97.72 KB (0%) 105 KB

@bardisg bardisg merged commit 37ac0ea into develop Feb 27, 2024
13 checks passed
@bardisg bardisg deleted the feature/sdk-949-update-msw-dependency branch February 27, 2024 07:01
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.

2 participants