From 9aca28063ef997c44c3c34346d6d61e0f6af3eac Mon Sep 17 00:00:00 2001 From: "chenjiawei.inizio" <289056872@qq.com> Date: Tue, 27 May 2025 14:52:20 +0800 Subject: [PATCH] chore: add e2e config (#280) * chore: open ssg * chore: add e2e base config case * chore: sync screenshot * chore: sync screenshot in linux * chore: render layout --- .github/workflows/e2e.yml | 32 ++++++++++ .github/workflows/sync-screenshot.yml | 49 +++++++++++++++ .gitignore | 3 + .../src/components/add-node/index.tsx | 1 + .../src/components/node-panel/node-list.tsx | 1 + apps/docs/rspress.config.ts | 22 ++----- common/config/rush/command-line.json | 18 ++++++ common/config/rush/pnpm-lock.yaml | 58 ++++++++++++++++++ cspell.json | 3 +- e2e/fixed-layout/.eslintrc.js | 6 ++ e2e/fixed-layout/package.json | 19 ++++++ e2e/fixed-layout/playwright.config.ts | 17 +++++ e2e/fixed-layout/tests/layout.spec.ts | 6 ++ .../homepage-linux.png | Bin 0 -> 61605 bytes e2e/fixed-layout/tsconfig.json | 22 +++++++ e2e/free-layout/.eslintrc.js | 15 +++++ e2e/free-layout/package.json | 20 ++++++ e2e/free-layout/playwright.config.ts | 17 +++++ e2e/free-layout/tests/layout.spec.ts | 8 +++ .../homepage-linux.png | Bin 0 -> 109341 bytes e2e/free-layout/tests/models/index.ts | 36 +++++++++++ e2e/free-layout/tests/node.spec.ts | 23 +++++++ e2e/free-layout/tsconfig.json | 22 +++++++ rush.json | 10 +++ 24 files changed, 389 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/e2e.yml create mode 100644 .github/workflows/sync-screenshot.yml create mode 100644 e2e/fixed-layout/.eslintrc.js create mode 100644 e2e/fixed-layout/package.json create mode 100644 e2e/fixed-layout/playwright.config.ts create mode 100644 e2e/fixed-layout/tests/layout.spec.ts create mode 100644 e2e/fixed-layout/tests/layout.spec.ts-snapshots/homepage-linux.png create mode 100644 e2e/fixed-layout/tsconfig.json create mode 100644 e2e/free-layout/.eslintrc.js create mode 100644 e2e/free-layout/package.json create mode 100644 e2e/free-layout/playwright.config.ts create mode 100644 e2e/free-layout/tests/layout.spec.ts create mode 100644 e2e/free-layout/tests/layout.spec.ts-snapshots/homepage-linux.png create mode 100644 e2e/free-layout/tests/models/index.ts create mode 100644 e2e/free-layout/tests/node.spec.ts create mode 100644 e2e/free-layout/tsconfig.json diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 00000000..e43e314f --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,32 @@ +name: E2E Tests + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + merge_group: + branches: [ "main" ] + +jobs: + e2e: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Rush Install + run: node common/scripts/install-run-rush.js install + + - name: Rush build + run: node common/scripts/install-run-rush.js build + + - name: Install Playwright Browsers + run: npx playwright install --with-deps + + - name: Run E2E tests + run: node common/scripts/install-run-rush.js e2e:test --verbose diff --git a/.github/workflows/sync-screenshot.yml b/.github/workflows/sync-screenshot.yml new file mode 100644 index 00000000..330f52bb --- /dev/null +++ b/.github/workflows/sync-screenshot.yml @@ -0,0 +1,49 @@ +name: Sync Screenshot +on: + workflow_dispatch + +concurrency: + group: "manual-sync-screenshot" + cancel-in-progress: false + +jobs: + e2e: + # can not update screenshot run on main. + if: github.ref_name != 'main' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Set Git user.name and user.email from trigger actor + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + + - name: Rush Install + run: node common/scripts/install-run-rush.js install + + - name: Rush build + run: node common/scripts/install-run-rush.js build + + - name: Install Playwright Browsers + run: npx playwright install --with-deps + + - name: Run E2E tests + run: node common/scripts/install-run-rush.js e2e:update-screenshot --verbose + + - name: Commit and push changes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git add . + if git diff-index --quiet HEAD; then + echo "No changes to commit" + else + git commit -m "chore: sync screenshot" + git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }} HEAD:${{ github.ref_name }} + fi diff --git a/.gitignore b/.gitignore index 240f4c66..bc0211d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# e2e results +test-results/ + # Logs *.log npm-debug.log* diff --git a/apps/demo-free-layout/src/components/add-node/index.tsx b/apps/demo-free-layout/src/components/add-node/index.tsx index 872c1a69..66bc3911 100644 --- a/apps/demo-free-layout/src/components/add-node/index.tsx +++ b/apps/demo-free-layout/src/components/add-node/index.tsx @@ -7,6 +7,7 @@ export const AddNode = (props: { disabled: boolean }) => { const addNode = useAddNode(); return (