Skip to content

chore(e2e): add an option to update snapshots #17

chore(e2e): add an option to update snapshots

chore(e2e): add an option to update snapshots #17

Workflow file for this run

name: Automation Testing (Draft)
on:
push:
branches: [ main, main-beta, epic/* ]
workflow_dispatch:
inputs:
updateSnapshots:
type: boolean
default: false
required: false
description: 'Update snapshots during the run on the current brunch'
env:
node-version: 20.x
DIFF_REPORT_BRANCH: diff-report
permissions:
contents: write
pages: none
deployments: none
pull-requests: write
jobs:
e2e-tests:
name: Automation Testing
runs-on: ubuntu-latest
if: ${{ !inputs.updateSnapshots }}
steps:
- uses: actions/checkout@v4
- name: Use Node v${{ env.node-version }}
uses: actions/setup-node@v4
with:
cache: 'npm'
node-version: ${{ env.node-version }}
- name: Install NPM Dependencies
run: npm ci
- name: Run Tests
run: npm run test:e2e
- name: Collect Report & Upload artifact
if: failure()
uses: actions/upload-artifact@v4
with:
name: automation-diff-report
path: e2e/.diff
- name: Deploy latest issued report to branch
if: failure()
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: e2e/.diff
publish_branch: ${{ env.DIFF_REPORT_BRANCH }}
- name: Render Report
if: always()
shell: bash
run: |
cat e2e/.diff/index.md >> $GITHUB_STEP_SUMMARY
e2e-tests-update-snapshots:
name: Automation Testing
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' && inputs.updateSnapshots }}
steps:
- uses: actions/checkout@v4
- name: Use Node v${{ env.node-version }}
uses: actions/setup-node@v4
with:
cache: 'npm'
node-version: ${{ env.node-version }}
- name: Install NPM Dependencies
run: npm ci
- name: Update Test Snapshots
run: npm run test:e2e -- -u
- name: Commit & Push Snapshot Changes
uses: actions/github-script@v5
with:
script: |
const git = require('simple-git')();
const currentBranch = '${{ github.ref }}'.split('/').pop();
await git.addConfig('user.email', '${{ github.actor }}@users.noreply.github.com');
await git.addConfig('user.name', '${{ github.actor }}');
await git.add('*.png');
await git.commit('test(e2e): update snapshots (via GitHub Actions))');
await git.push('origin', currentBranch);