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

Add end to end test suite to test NextJS app in Edge runtime w/TS client #304

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

aulorbe
Copy link
Collaborator

@aulorbe aulorbe commented Oct 16, 2024

Problem

We do not currently have a good way to test how our client behaves end to end in different environments. One of the chief problems our users have brought to our attention in the past is that some functionalities do not work in certain runtimes, e.g. Edge or Bun, and/or with certain frameworks, e.g. NextJS.

Solution

Build an external application in a runtime and framework known to have caused problems in the past and test our client from the end-user's perspective.

This PR introduces and end-to-end test suite that interacts with an external application written using the NextJS framework and the Edge runtime.

Note: the app is automagically run in Edge by way of it using middleware (middleware.ts), and the Headers() API.

Overview of changes

  • We now have a public repo that contains a super simple application that builds a Pinecone serverless index, seeds it with data, and queries that data. We plan to add more operations in the near future; this is just a start.
  • This sample application creates an API endpoint that our client repo can send a POST request to and assert on the response. If the endpoint fails to deliver the expected response, we know that something is wrong with the most recent changes we are proposing to introduce in the client.
  • This PR enables 2 types of interaction with the sample application:
    • Local end-to-end tests: for local runs, there is a new bash script that devs can execute. This will spin up the application on their localhost:3000. Once the app is up and running, they can hit the endpoint with cURL, Postman, etc.
    • CI end-to-end tests: for CI runs, we will now run this end-to-end test automatically by way of adding it the testing.yml file that is run for each push to an open PR. In CI, the Github workflow and action hit the application's endpoint and assert on its response. In this environment, the Github action is hitting a version of the app that is hosted on Pinecone's Enterprise Vercel account. Note: if this app's Vercel deployment gets rolled back for any reason, the CI tests will fail.
  • There is a new CONTRIBUTING.md file with some info on this new test suite + the other existing ones, as well as a new README in the end-to-end dir itself with more in depth information.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

If reviewers can pull down the code in this branch and try to run the end-to-end tests locally, that'd be great.

To Dos

I'll add a README and a CONTRIBUTING file to the external app

@aulorbe aulorbe removed the request for review from austin-denoble October 16, 2024 23:05
@aulorbe aulorbe changed the title Merge new workflow to main in order to test [Draft] Oct 16, 2024
@aulorbe aulorbe changed the title [Draft] [Draft] e2e Oct 17, 2024
@@ -27,27 +31,68 @@ runs:
uses: GuillaumeFalourd/clone-github-repo-action@main
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just a note for the previous step: npm pack packages up the existing code on the existing branch, so it'll run the code devs are proposing to merge in their PR, rather than whatever code is on npm etc. This removes the need for us to merge things before testing them end to end.

exit 1
fi

if [ "$match_count" -lt 1 ]; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is where we assert on the response in CI


response=$(curl --silent --location --request POST "$API_URL" --header "PINECONE_API_KEY: $API_KEY")

indexName=$(echo "$response" | jq -r '.indexName')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Index names are randomized in the app. We then save the index name to the GITHUB_ENV environment variable file, so that we can delete them later -- this ensures we can have simultaneous runs of this workflow, from creating the index to deleting it later

@aulorbe aulorbe changed the title [Draft] e2e Add end to end test suite to test NextJS app in Edge runtime w/TS client Oct 18, 2024
# Hop into ts-client-e2e-tests repo, install deps, link local ts-client repo, and start the Next.js server
pushd "$dir/ts-client-e2e-tests"
npm install
npm link @pinecone-database/pinecone
Copy link
Collaborator Author

@aulorbe aulorbe Oct 18, 2024

Choose a reason for hiding this comment

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

This will overwrite the portion in the app's package.json that says "@pinecone-database/pinecone": "^3.0.4-rc.2024-10.0". Instead, it'll link to your local version.

You must run it after npm install, or else npm install will change package.json back to "^3.0.4-rc.2024-10.0", since that's the latest version up on npm as of this writing.

next dev
popd

#npm uninstall -g next # Can comment out if do not want to uninstall the global Next.js package
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do have to install NextJS globally or else the next dev command (to spin up the app on your localhost:3000 won't work when run from the ts-client repo, which is where this bash file is being executed. If you don't want Next globally, you can uncomment line 54 and uninstall it.

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.

1 participant