Handle edge cases in E2E

This commit is contained in:
Sidharth Vinod
2024-01-19 19:04:25 +05:30
parent 6f205f89b2
commit a964af67ec
2 changed files with 27 additions and 23 deletions

View File

@@ -1,3 +1,9 @@
# We use github cache to save snapshots between runs.
# For PRs and MergeQueues, the target commit is used, and for push events, github.event.previous is used.
# If a snapshot for a given Hash is not found, we checkout that commit, run the tests and cache the snapshots.
# These are then downloaded before running the E2E, providing the reference snapshots.
# If there are any errors, the diff image is uploaded to artifacts, and the user is notified.
name: E2E name: E2E
on: on:
@@ -9,7 +15,8 @@ permissions:
contents: read contents: read
env: env:
targetHash: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event_name == 'merge_group' && github.event.merge_group.base.sha || github.event.before }} # For PRs and MergeQueues, the target commit is used, and for push events, github.event.previous is used.
targetHash: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }}
jobs: jobs:
cache: cache:
@@ -30,6 +37,7 @@ jobs:
path: ./cypress/snapshots path: ./cypress/snapshots
key: ${{ runner.os }}-snapshots-${{ env.targetHash }} key: ${{ runner.os }}-snapshots-${{ env.targetHash }}
# If a snapshot for a given Hash is not found, we checkout that commit, run the tests and cache the snapshots.
- name: Switch to base branch - name: Switch to base branch
if: ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }} if: ${{ steps.cache-snapshot.outputs.cache-hit != 'true' }}
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -44,6 +52,8 @@ jobs:
start: pnpm run dev start: pnpm run dev
wait-on: 'http://localhost:9000' wait-on: 'http://localhost:9000'
browser: chrome browser: chrome
spec:
cypress/integration/rendering/sequencediagram.spec.js
e2e: e2e:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -64,6 +74,7 @@ jobs:
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
# These cached snapshots are downloaded, providing the reference snapshots.
- name: Cache snapshots - name: Cache snapshots
id: cache-snapshot id: cache-snapshot
uses: actions/cache/restore@v3 uses: actions/cache/restore@v3
@@ -87,6 +98,8 @@ jobs:
# e.g. if this action was run from a fork # e.g. if this action was run from a fork
record: ${{ secrets.CYPRESS_RECORD_KEY != '' }} record: ${{ secrets.CYPRESS_RECORD_KEY != '' }}
parallel: ${{ secrets.CYPRESS_RECORD_KEY != '' }} parallel: ${{ secrets.CYPRESS_RECORD_KEY != '' }}
spec:
cypress/integration/rendering/sequencediagram.spec.js
env: env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
VITEST_COVERAGE: true VITEST_COVERAGE: true
@@ -104,9 +117,10 @@ jobs:
verbose: true verbose: true
token: 6845cc80-77ee-4e17-85a1-026cd95e0766 token: 6845cc80-77ee-4e17-85a1-026cd95e0766
# We upload the artifacts into numbered archives to prevent overwriting
- name: Upload Artifacts - name: Upload Artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
if: ${{ failure() && steps.cypress.conclusion == 'failure' }} if: ${{ always() }}
with: with:
name: snapshots-${{ matrix.containers }} name: snapshots-${{ matrix.containers }}
retention-days: 1 retention-days: 1
@@ -117,6 +131,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: ${{ always() }} if: ${{ always() }}
steps: steps:
# Download all snapshot artifacts and merge them into a single folder
- name: Download All Artifacts - name: Download All Artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
@@ -124,31 +139,32 @@ jobs:
pattern: snapshots-* pattern: snapshots-*
merge-multiple: true merge-multiple: true
# For successful push events, we save the snapshots cache
- name: Save snapshots cache - name: Save snapshots cache
id: cache-upload id: cache-upload
if: ${{ github.event_name == 'push' }} if: ${{ github.event_name == 'push' && needs.e2e.result != 'failure' }}
uses: actions/cache/save@v3 uses: actions/cache/save@v3
with: with:
path: | path: ./snapshots
./cypress/snapshots
!./**/__diff_output__/*
key: ${{ runner.os }}-snapshots-${{ github.event.after }} key: ${{ runner.os }}-snapshots-${{ github.event.after }}
- if: ${{ failure() }} - name: Flatten images to a folder
if: ${{ needs.e2e.result == 'failure' }}
run: | run: |
mkdir errors mkdir errors
cd snapshots cd snapshots
find . -mindepth 2 -type d -name "*__diff_output__*" -exec sh -c 'mv "$0"/*.png ../errors/' {} \; find . -mindepth 2 -type d -name "*__diff_output__*" -exec sh -c 'mv "$0"/*.png ../errors/' {} \;
- name: Upload Error snapshots - name: Upload Error snapshots
if: ${{ failure() }} if: ${{ needs.e2e.result == 'failure' }}
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
id: upload-artifacts id: upload-artifacts
with: with:
name: error-snapshots name: error-snapshots
retention-days: 10 retention-days: 10
path: errors/ path: errors/
- name: Notify Users - name: Notify Users
if: ${{ failure() }} if: ${{ needs.e2e.result == 'failure' }}
run: | run: |
echo "::error title=Visual tests failed::You can view images that failed by downloading the error-snapshots artifact: ${{ steps.upload-artifacts.outputs.artifact-url }}" echo "::error title=Visual tests failed::You can view images that failed by downloading the error-snapshots artifact: ${{ steps.upload-artifacts.outputs.artifact-url }}"

View File

@@ -1,12 +0,0 @@
import { imgSnapshotTest } from '../../helpers/util.ts';
describe('Flowchart', () => {
it('34: testing the label width in percy', () => {
imgSnapshotTest(
`graph TD
A[Christmas]
`,
{ theme: 'forest', fontFamily: '"Noto Sans SC", sans-serif' }
);
});
});