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

chore(tests): Standardize imports and add page navigavion helper #16914

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

svanaeinars
Copy link
Member

@svanaeinars svanaeinars commented Nov 18, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new asynchronous function, createPageAndNavigate, for creating and navigating to a page within a specified browser context.
  • Bug Fixes
    • Adjusted export statements to ensure correct access to test and expect, while converting Page, Locator, and BrowserContext to type-only exports.

@svanaeinars svanaeinars requested a review from a team as a code owner November 18, 2024 10:13
Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Walkthrough

The changes in this pull request involve modifications to the export statements in the index.ts file, transitioning Page, Locator, and BrowserContext to type-only exports while retaining the exports of test and expect. Additionally, a new function createPageAndNavigate is introduced in the api-tools.ts file, which utilizes BrowserContext to create a new page and navigate to a specified URL.

Changes

File Path Change Summary
libs/testing/e2e/src/index.ts Updated exports: removed direct exports of Page, Locator, BrowserContext; added type-only exports for them.
libs/testing/e2e/src/lib/helpers/api-tools.ts Added new function createPageAndNavigate that takes BrowserContext and a URL, creates a page, and navigates to it.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BrowserContext
    participant Page

    User->>BrowserContext: Create a new context
    BrowserContext->>Page: createPageAndNavigate(url)
    Page-->>BrowserContext: New page created
    Page->>User: Navigate to URL
Loading

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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.45%. Comparing base (b19bea9) to head (0492e27).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16914      +/-   ##
==========================================
- Coverage   36.46%   36.45%   -0.01%     
==========================================
  Files        6903     6881      -22     
  Lines      144575   144116     -459     
  Branches    41282    41131     -151     
==========================================
- Hits        52715    52541     -174     
+ Misses      91860    91575     -285     
Flag Coverage Δ
api 3.34% <ø> (ø)
application-system-api 41.02% <ø> (ø)
application-template-api-modules 27.73% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 41 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b19bea9...0492e27. Read the comment docs.

@svanaeinars svanaeinars added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 18, 2024
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

🧹 Outside diff range and nitpick comments (2)
libs/testing/e2e/src/index.ts (1)

12-13: Well-structured separation of runtime and type exports!

This change improves tree-shaking by clearly separating runtime exports (test, expect) from type-only exports (Page, Locator, BrowserContext). This approach ensures that type information doesn't bloat the production bundle while maintaining strong typing during development.

libs/testing/e2e/src/lib/helpers/api-tools.ts (1)

25-39: Consider enhancing the navigation helper with additional options.

The implementation is clean and well-documented. Consider these improvements for better robustness:

 export const createPageAndNavigate = async (
   context: BrowserContext,
   url: string,
+  options?: {
+    timeout?: number;
+    waitUntil?: 'load'|'domcontentloaded'|'networkidle';
+  }
 ) => {
   const page = await context.newPage()
-  await page.goto(url)
+  try {
+    await page.goto(url, {
+      timeout: options?.timeout,
+      waitUntil: options?.waitUntil ?? 'load'
+    })
+  } catch (error) {
+    await page.close()
+    throw error
+  }
   return page
 }

This would:

  • Add configurable timeout for slow networks
  • Allow specifying when navigation is considered complete
  • Clean up resources on navigation failure
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d89ae9c and e623614.

📒 Files selected for processing (2)
  • libs/testing/e2e/src/index.ts (1 hunks)
  • libs/testing/e2e/src/lib/helpers/api-tools.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/testing/e2e/src/index.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/testing/e2e/src/lib/helpers/api-tools.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (3)
libs/testing/e2e/src/index.ts (1)

13-13: Verify type-only usage across the codebase

Let's ensure that Page, Locator, and BrowserContext are only used as types throughout the codebase.

✅ Verification successful

Let me gather more specific information about how these types are actually being used in the codebase.


Type exports are used correctly and safely across the codebase

The verification shows that:

  1. The types Page, Locator, and BrowserContext are only used as type annotations and parameters in test files
  2. The only runtime usage found is in pdf.worker.min.mjs which is an external PDF.js library file, not application code
  3. All imports of these types are properly scoped with type keyword in the export statement
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that Page, Locator, and BrowserContext are only used as types

# Check for type usage (should find matches)
echo "Checking for type usage..."
ast-grep --pattern 'type $name = Page;' 
ast-grep --pattern 'type $name = Locator;'
ast-grep --pattern 'type $name = BrowserContext;'
ast-grep --pattern 'function $name($param: Page)' 
ast-grep --pattern 'function $name($param: Locator)'
ast-grep --pattern 'function $name($param: BrowserContext)'

# Check for potential runtime usage (should not find matches)
echo "Checking for potential runtime usage..."
rg -l 'new (Page|Locator|BrowserContext)\(' 
rg -l 'instanceof (Page|Locator|BrowserContext)'

Length of output: 640


Script:

#!/bin/bash
# Search for all imports and type references of Page, Locator, and BrowserContext
echo "Checking imports and type references..."
rg -A 2 "import.*\{.*(Page|Locator|BrowserContext).*\}" --type ts

echo "\nChecking type annotations..."
rg ":\s*(Page|Locator|BrowserContext)[\s,\)]" --type ts

# Check the specific file that showed runtime usage
echo "\nChecking the pdf.worker.min.mjs file..."
head -n 20 apps/web/public/assets/pdf.worker.min.mjs

Length of output: 118564

libs/testing/e2e/src/lib/helpers/api-tools.ts (2)

Line range hint 1-24: LGTM! Clean imports and well-documented existing function.

The code demonstrates good TypeScript practices with proper type imports and comprehensive JSDoc documentation.


Line range hint 1-39: Excellent compliance with library coding guidelines.

The implementation successfully meets all requirements for library code:

  • ✓ Functions are reusable across different NextJS e2e test suites
  • ✓ Proper TypeScript types and documentation
  • ✓ Tree-shakeable exports with no side effects

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 18, 2024

Datadog Report

All test runs 43affdb 🔗

3 Total Test Services: 0 Failed, 3 Passed
➡️ Test Sessions change in coverage: 28 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.25s 1 no change Link
application-system-api 0 0 0 112 2 3m 35.05s 1 no change Link
application-template-api-modules 0 0 0 116 0 2m 43.24s 1 no change Link

@kodiakhq kodiakhq bot merged commit cbecc81 into main Nov 18, 2024
52 checks passed
@kodiakhq kodiakhq bot deleted the chore/standardize-imports-and-add-page-navigation-e2e branch November 18, 2024 13:13
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants