-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
feat: introduce cypress e2e tests #9520
Open
perzeuss
wants to merge
2
commits into
langgenius:main
Choose a base branch
from
perzeuss:feat/9253-introduce-cypress-e2e-integration-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,627
−1,712
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Cypress Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
e2e-tests: | ||
runs-on: ubuntu-latest | ||
env: | ||
CYPRESS_COMMAND_TIMEOUT: ${{ vars.CYPRESS_COMMAND_TIMEOUT }} | ||
steps: | ||
- name: Checkout (GitHub) | ||
uses: actions/checkout@v4 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.CYPRESS_CONTAINER_REGISTRY_TOKEN }} | ||
|
||
- name: Build and run dev container task | ||
uses: devcontainers/[email protected] | ||
with: | ||
imageName: ghcr.io/${{ vars.DOCKER_NAMESPACE }}/${{ vars.DEVCONTAINER_IMAGE_NAME }} | ||
cacheFrom: ghcr.io/${{ vars.DOCKER_NAMESPACE }}/${{ vars.DEVCONTAINER_IMAGE_NAME }} | ||
push: always | ||
runCmd: cd web && yarn test:e2e:ci | ||
|
||
- name: Upload Cypress videos | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: cypress-videos | ||
path: web/cypress/videos/**/*.mp4 | ||
if: failure() | ||
|
||
- name: Upload Cypress screenshots | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: cypress-screenshots | ||
path: web/cypress/screenshots/**/*.png | ||
if: failure() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This Docker Compose file extends services from docker-compose.yaml | ||
# specifically for running end-to-end (e2e) tests. | ||
# It simplifies configuration by overriding certain values here. | ||
# | ||
# Additionally, the volume mounts defined in docker-compose.yaml | ||
# are customizable to ensure that test data is stored in docker/volumes/cypress. | ||
|
||
name: dify-cypress | ||
services: | ||
api: | ||
extends: | ||
file: docker-compose.yaml | ||
service: api | ||
ports: | ||
- 5001:5001 | ||
|
||
db: | ||
extends: | ||
file: docker-compose.yaml | ||
service: db | ||
ports: | ||
- 54321:5432 | ||
|
||
redis: | ||
extends: | ||
file: docker-compose.yaml | ||
service: redis | ||
|
||
networks: | ||
ssrf_proxy_network: | ||
driver: bridge | ||
internal: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor' | ||
import { createEsbuildPlugin } from '@badeball/cypress-cucumber-preprocessor/esbuild' | ||
import createBundler from '@bahmutov/cypress-esbuild-preprocessor' | ||
import { defineConfig } from 'cypress' | ||
import { PostgresClient } from './cypress/support/db' | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
baseUrl: 'http://localhost:3000', | ||
specPattern: '**/*.feature', | ||
video: true, | ||
env: { | ||
SLOW_DOWN: false, | ||
}, | ||
// it might take a while for nextjs to compile the page on first visit | ||
defaultCommandTimeout: Number(process.env.CYPRESS_COMMAND_TIMEOUT) || 10000, | ||
async setupNodeEvents( | ||
on: Cypress.PluginEvents, | ||
config: Cypress.PluginConfigOptions, | ||
): Promise<Cypress.PluginConfigOptions> { | ||
await addCucumberPreprocessorPlugin(on, config) | ||
|
||
on( | ||
'file:preprocessor', | ||
createBundler({ | ||
plugins: [createEsbuildPlugin(config)], | ||
}), | ||
) | ||
|
||
const dbInstance = new PostgresClient() | ||
|
||
on('task', { | ||
runQuery: async ({ query, params }: { query: string; params?: any[] }) => { | ||
// This will only create a new connection if it's not already connected | ||
await dbInstance.connect({ | ||
user: 'postgres', | ||
host: 'localhost', | ||
database: 'dify', | ||
password: 'difyai123456', | ||
port: 54321, | ||
}) | ||
return dbInstance.query(query, params) | ||
}, | ||
}) | ||
|
||
on('after:run', async () => { | ||
// This will be called once after all tests | ||
await dbInstance.close() | ||
}) | ||
|
||
return config | ||
}, | ||
}, | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@takatost The frontend team rarely use devcontainer, and backend team don't care about e2e test, maybe remove these change will be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback! I understand the concerns about adding Cypress dependencies to the Dockerfile for the devcontainer. However, In my opinion, we have enough reasons to keep them: