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: added teardown script to E2E test suite #1162

Conversation

JohnAllenTech
Copy link
Contributor

@JohnAllenTech JohnAllenTech commented Oct 20, 2024

✨ Codu Pull Request 💻

Ah... its an issue that we will start to see people complain about

If you run E2E tests over and over again locally you end up with a article page that looks like this

image

Pull Request details

  • Added a teardown script that will run after all other tests have finished
  • Reason for the raw postgres client is our drizzle db is set up to only be able to run server side.
  • One issue is if you are using the VS code playwright plugin it doesnt automatically run the teardown script for some reason. npx playwright test does however run it automatically.

You can manually run it by clicking 'Run global teardown'

image

I have opened an issue for this with playwright here

Any Breaking changes

  • None

Associated Screenshots

  • None

@JohnAllenTech JohnAllenTech requested a review from a team as a code owner October 20, 2024 21:16
Copy link

vercel bot commented Oct 20, 2024

@JohnAllenTech is attempting to deploy a commit to the Codú Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 20, 2024

Walkthrough

The changes introduce a new file teardown.ts for end-to-end (E2E) testing, which implements a database cleanup function. This function checks for necessary environment variables, connects to a PostgreSQL database, and deletes posts and comments associated with a specific user to maintain a clean database state between test runs. Additionally, the playwright.config.ts file is updated to include a globalTeardown property that points to the teardown.ts script, ensuring it runs after all tests.

Changes

File Change Summary
e2e/teardown.ts Added a new file with an asynchronous teardown function for database cleanup during E2E tests.
playwright.config.ts Added globalTeardown property pointing to ./e2e/teardown.ts in the Playwright configuration.

Possibly related PRs

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐇 In the garden where bunnies play,
A cleanup script has come our way!
With posts and comments swept away,
Our tests will run without dismay.
So hop along, let’s cheer hooray! 🎉


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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
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: 1

🧹 Outside diff range and nitpick comments (3)
e2e/teardown.ts (3)

1-4: Consider adding type information to imports

The imports look good and are necessary for the script's functionality. However, consider adding type information to improve type safety and developer experience.

You could update the imports as follows:

import dotenv from "dotenv";
import postgres from "postgres";

to:

import dotenv from "dotenv";
import postgres from "postgres";
import type { Sql } from "postgres";

This change will allow you to properly type the db variable later in the code.


6-10: Approve environment variable check, suggest error handling for DB connection

The environment variable check is a good practice. However, consider adding error handling for the database connection initialization.

You could update the code as follows:

export const teardown = async () => {
  try {
    if (!process.env.DATABASE_URL || !process.env.E2E_USER_ID)
      throw new Error("Missing env variables for DB clean up script");
    
    let db: Sql;
    try {
      db = postgres(process.env.DATABASE_URL as string);
    } catch (error) {
      throw new Error(`Failed to connect to the database: ${error.message}`);
    }

    // ... rest of the function
  } catch (err) {
    console.error("Error while cleaning up DB after E2E test run", err);
  }
};

This change adds specific error handling for database connection issues.


21-27: Use console.error for error logging, exports look good

The error handling and exports look good overall. However, consider using console.error for error logging instead of console.log.

Update the error logging as follows:

} catch (err) {
  console.error("Error while cleaning up DB after E2E test run", err);
}

This change makes it easier to distinguish between regular logs and error logs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 77aa243 and cee4687.

📒 Files selected for processing (2)
  • e2e/teardown.ts (1 hunks)
  • playwright.config.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
playwright.config.ts (2)

Line range hint 1-78: Summary: Configuration change looks good

The addition of the globalTeardown property is the only change in this file, and it correctly implements the requirement for a teardown script as described in the PR objectives. The rest of the configuration remains unchanged, which is appropriate for this specific enhancement.


13-13: LGTM! Verify the existence of the teardown script.

The addition of the globalTeardown property is correct and aligns with the PR objective. This will ensure that the teardown script runs after all tests are completed.

Let's verify the existence of the teardown script:

✅ Verification successful

Verified: Teardown script exists.

The teardown script e2e/teardown.ts exists at the specified path, confirming that the globalTeardown configuration is correctly set.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the teardown script

# Test: Check if the teardown script exists
if fd -p "e2e/teardown.ts$"; then
    echo "Teardown script found."
else
    echo "Teardown script not found. Please ensure it exists at the specified path."
fi

Length of output: 97

@JohnAllenTech JohnAllenTech changed the title chore: added teardown script chore: added teardown script to E2E test suite Oct 20, 2024
Copy link
Contributor

@NiallJoeMaher NiallJoeMaher left a comment

Choose a reason for hiding this comment

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

Nice!

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

Successfully merging this pull request may close these issues.

3 participants