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

ci: uploads Cypress screenshots and videos on failure #1178

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ jobs:
yarn build:staging
- run: |
yarn preview:built &
yarn run test:browser
CYPRESS_video=true yarn run test:browser
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-artifacts
retention-days: ${{ github.event_name == 'pull_request' && 3 || 30 }}
path: |
cypress/screenshots
cypress/videos

post-checks:
# There is a branch protection rule on the repo that requires "branch-protection" to
Expand Down
10 changes: 9 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import createBundler from '@bahmutov/cypress-esbuild-preprocessor'
import { defineConfig } from 'cypress'
import cypressFailFast from 'cypress-fail-fast/plugin'
import dotenv from 'dotenv'
import fs from 'node:fs'

const env = dotenv.config().parsed as {[key: string]: string}

export default defineConfig({
e2e: {
specPattern: '**/*.feature',
experimentalRunAllSpecs: true,
// TODO Env var
// Can be turned on via CLI using `CYPRESS_video=true yarn test:browser`
video: false,
async setupNodeEvents(on, config) {
// propagate env to Cypress.env
Expand Down Expand Up @@ -43,6 +44,13 @@ export default defineConfig({
}),
)

// Deletes videos of successful specs to avoid uploading them as GitHub artifacts
on('after:spec', (_spec, results) => {
if (results && results.video && results.stats.failures === 0) {
fs.unlinkSync(results.video)
}
})

cypressFailFast(on, config)

// Make sure to return the config object as it might have been modified by the plugin.
Expand Down