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 Frontend Tests #1571

Merged
merged 41 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8d35fe8
Add TypeScript test workflow
ogabrielluiz Mar 27, 2024
0e356fb
Update follow-redirects and katex versions
ogabrielluiz Mar 27, 2024
6d684a1
Add Python setup and Poetry installation for backend
ogabrielluiz Mar 27, 2024
b9bf53e
Update Poetry version and setup Python in workflows
ogabrielluiz Mar 27, 2024
8768061
Add Poetry installation step to GitHub Actions workflow
ogabrielluiz Mar 27, 2024
2ee081a
Add Playwright report artifact upload and improve test script
ogabrielluiz Mar 27, 2024
0d272be
Update Playwright test configuration and add global teardown script
ogabrielluiz Mar 27, 2024
d6b8c67
Update path for playwright-report directory
ogabrielluiz Mar 27, 2024
e44a70f
Update timeout value in playwright.config.ts
ogabrielluiz Mar 27, 2024
91192a0
Update page URLs in end-to-end tests
ogabrielluiz Mar 27, 2024
48f9f5e
Update GitHub Actions workflow and Playwright configuration
ogabrielluiz Mar 27, 2024
2504550
Update TypeScript test workflow
ogabrielluiz Mar 27, 2024
9e56083
Add pattern and merge-multiple options to artifact download
ogabrielluiz Mar 27, 2024
bc7d2c3
Update TypeScript test workflow to install Poetry
ogabrielluiz Mar 27, 2024
801cd7e
Add cache steps for Playwright and Poetry
ogabrielluiz Mar 27, 2024
de44e95
Update PLAYWRIGHT_BROWSERS_PATH in TypeScript test workflow
ogabrielluiz Mar 27, 2024
408cdac
Add 'stuff/' to .gitignore
ogabrielluiz Mar 27, 2024
010b3d5
Remove caching of Poetry virtualenv
ogabrielluiz Mar 27, 2024
50184b6
Update frontend tests to use Playwright for UI testing
ogabrielluiz Mar 27, 2024
d08c29b
Add global teardown for removing temp database
ogabrielluiz Mar 27, 2024
78269f8
Add cache-hit condition to setup-node and setup-python steps
ogabrielluiz Mar 27, 2024
2c23bc0
Add new file to .gitignore and update ignored files
ogabrielluiz Mar 27, 2024
090da0e
Update playwright cache key in TypeScript test workflow
ogabrielluiz Mar 27, 2024
c76056e
Update path for blob-report in GitHub workflow
ogabrielluiz Mar 27, 2024
5b1057d
Update path for playwright cache
ogabrielluiz Mar 27, 2024
ca53dde
Update dependency installation in workflows
ogabrielluiz Mar 27, 2024
621a2a2
Update baseURL in playwright.config.ts
ogabrielluiz Mar 27, 2024
47a99ed
Update baseURL in playwright.config.ts
ogabrielluiz Mar 27, 2024
ebda6d6
Refactor test timeouts
ogabrielluiz Mar 27, 2024
f2bdd35
Remove playwright-report index.html file
ogabrielluiz Mar 27, 2024
b908cf0
Add npm run start command to playwright.config.ts
ogabrielluiz Mar 27, 2024
ed55ffc
Update npm start command in playwright.config.ts
ogabrielluiz Mar 27, 2024
b3513f6
Update Playwright browser caching and installation
ogabrielluiz Mar 27, 2024
daf447a
Update playwright cache path
ogabrielluiz Mar 27, 2024
933e3ec
Update playwright cache path
ogabrielluiz Mar 27, 2024
e34cad0
Update actions/cache version to v4
ogabrielluiz Mar 27, 2024
e3df4e0
Update Playwright cache key to use package-lock.json
ogabrielluiz Mar 27, 2024
fa575d9
Update Playwright cache and install dependencies
ogabrielluiz Mar 27, 2024
18a77eb
Fix typo in Playwright installation command
ogabrielluiz Mar 27, 2024
bb81d24
Fix npm ci command in TypeScript test workflow
ogabrielluiz Mar 27, 2024
3eb0725
Update TypeScript test workflow
ogabrielluiz Mar 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/python_test.yml
@@ -0,0 +1,43 @@
name: test

on:
push:
branches: [main]
paths:
- "poetry.lock"
- "pyproject.toml"
- "src/backend/**"
pull_request:
branches: [dev]
paths:
- "poetry.lock"
- "pyproject.toml"
- "src/backend/**"

env:
POETRY_VERSION: "1.8.2"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry==$POETRY_VERSION
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: poetry install
- name: Run unit tests
run: |
make tests
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -15,7 +15,7 @@ on:
- "src/backend/**"

env:
POETRY_VERSION: "1.5.0"
POETRY_VERSION: "1.8.2"

jobs:
build:
Expand All @@ -37,7 +37,9 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install dependencies
run: poetry install
run: |
poetry env use ${{ matrix.python-version }}
poetry install
- name: Run unit tests
run: |
make tests
149 changes: 149 additions & 0 deletions .github/workflows/typescript_test.yml
@@ -0,0 +1,149 @@
name: Run Frontend Tests

on:
pull_request:
paths:
- "src/frontend/**"

env:
POETRY_VERSION: "1.8.2"
NODE_VERSION: "21"
PYTHON_VERSION: "3.10"
# Define the directory where Playwright browsers will be installed.
# Adjust if your project uses a different path.
PLAYWRIGHT_BROWSERS_PATH: "ms-playwright"

jobs:
setup-and-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
id: setup-node
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"

- name: Install Node.js dependencies
run: |
cd src/frontend
npm ci
if: ${{ steps.setup-node.outputs.cache-hit != 'true' }}

# Attempt to restore the correct Playwright browser binaries based on the
# currently installed version of Playwright (The browser binary versions
# may change with Playwright versions).
# Note: Playwright's cache directory is hard coded because that's what it
# says to do in the docs. There doesn't appear to be a command that prints
# it out for us.
# - uses: actions/cache@v4
# id: playwright-cache
# with:
# path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
# key: "${{ runner.os }}-playwright-${{ hashFiles('src/frontend/package-lock.json') }}"
# # As a fallback, if the Playwright version has changed, try use the
# # most recently cached version. There's a good chance that at least one
# # of the browser binary versions haven't been updated, so Playwright can
# # skip installing that in the next step.
# # Note: When falling back to an old cache, `cache-hit` (used below)
# # will be `false`. This allows us to restore the potentially out of
# # date cache, but still let Playwright decide if it needs to download
# # new binaries or not.
# restore-keys: |
# ${{ runner.os }}-playwright-
- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('src/frontend/package-lock.json') }}
- name: Install Frontend dependencies
run: |
cd src/frontend
npm ci

- name: Install Playwright's browser binaries
run: |
cd src/frontend
npx playwright install --with-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
- name: Install Playwright's dependencies
run: |
cd src/frontend
npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit != 'true'

# If the Playwright browser binaries weren't able to be restored, we tell
# paywright to install everything for us.
# - name: Install Playwright's dependencies
# if: steps.playwright-cache.outputs.cache-hit != 'true'
# run: npx playwright install --with-deps

- name: Install Poetry
run: pipx install "poetry==${{ env.POETRY_VERSION }}"

- name: Set up Python
uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "poetry"

- name: Install Python dependencies
run: |
poetry env use ${{ env.PYTHON_VERSION }}
poetry install
if: ${{ steps.setup-python.outputs.cache-hit != 'true' }}

- name: Run Playwright Tests
run: |
cd src/frontend
npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}

- name: Upload blob report to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: blob-report-${{ matrix.shardIndex }}
path: src/frontend/blob-report
retention-days: 1

merge-reports:
needs: setup-and-test
runs-on: ubuntu-latest
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v4
with:
path: all-blob-reports
pattern: blob-report-*
merge-multiple: true

- name: Merge into HTML Report
run: |
npx playwright merge-reports --reporter html ./all-blob-reports

- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report--attempt-${{ github.run_attempt }}
path: playwright-report
retention-days: 14
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -262,3 +262,5 @@ src/backend/base/langflow/frontend/
.docker
scratchpad*
chroma*/*
stuff/*
src/frontend/playwright-report/index.html
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -47,9 +47,9 @@ run_frontend:

tests_frontend:
ifeq ($(UI), true)
cd src/frontend && ./run-tests.sh --ui
cd src/frontend && npx playwright test --ui --project=chromium
else
cd src/frontend && ./run-tests.sh
cd src/frontend && npx playwright test --project=chromium
endif

run_cli:
Expand Down
27 changes: 0 additions & 27 deletions src/frontend/.github/workflows/playwright.yml

This file was deleted.

12 changes: 6 additions & 6 deletions src/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions src/frontend/playwright-report/index.html

This file was deleted.

69 changes: 31 additions & 38 deletions src/frontend/playwright.config.ts
Expand Up @@ -12,26 +12,30 @@ import { defineConfig, devices } from "@playwright/test";
export default defineConfig({
testDir: "./tests",
/* Run tests in files in parallel */
fullyParallel: false,
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 2 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
["html", { open: "never", outputFolder: "playwright-report/test-results" }],
],
timeout: 120 * 1000,
// reporter: [
// ["html", { open: "never", outputFolder: "playwright-report/test-results" }],
// ],
reporter: process.env.CI ? "blob" : "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: "http://127.0.0.1:3000",
baseURL: "http://localhost:3000/",

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

globalTeardown: require.resolve("./tests/globalTeardown.ts"),

/* Configure projects for major browsers */
projects: [
{
Expand All @@ -48,39 +52,28 @@ export default defineConfig({
// name: "webkit",
// use: { ...devices["Desktop Safari"] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: [
// {
// command: "npm run backend",
// reuseExistingServer: !process.env.CI,
// timeout: 120 * 1000,
// },
// {
// command: "npm run start",
// url: "http://127.0.0.1:3000",
// reuseExistingServer: !process.env.CI,
// },
// ],
webServer: [
{
command:
"poetry run uvicorn --factory langflow.main:create_app --host 127.0.0.1 --port 7860",
port: 7860,
env: {
LANGFLOW_DATABASE_URL: "sqlite:///./temp",
LANGFLOW_AUTO_LOGIN: "true",
},
stdout: "ignore",

reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
},
{
command: "npm start",
port: 3000,
env: {
VITE_PROXY_TARGET: "http://127.0.0.1:7860",
},
},
],
});