Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active March 8, 2026 16:07
Show Gist options
  • Select an option

  • Save vielhuber/83fa11d9694af7a38c8775749bc5d4f7 to your computer and use it in GitHub Desktop.

Select an option

Save vielhuber/83fa11d9694af7a38c8775749bc5d4f7 to your computer and use it in GitHub Desktop.
cypress #js

SETUP

  • apt-get install libgtk-3-0t64 libgbm-dev libnotify-dev libnss3 libxss1 libasound2t64 libxtst6 xauth xvfb
  • git lfs install
  • mkdir -d /var/www/project/path/to/cypress
  • cd /var/www/project/path/to/cypress

PREPARE SEED FROM SQL

  • syncdb custom-production-local
  • ./db.sh prepare

CREATE TEST

  • CI=true php -S 0.0.0.0:8042 -t /var/www/project
  • Chrome: http://localhost:8042
  • Network > Preserve log: an
  • Record steps
  • Right click > Copy > Copy all as HAR (sanitized)
  • Copy to /recordings/YYYY-MM-DD.har

RUN TEST

  • npm run cypress:open
  • npm run cypress:run
  • npm run cypress:run -- --spec "tests/basic.js"

FILES

.gitignore

cypress/cypress.env.json
cypress/cypress/*.sql

cypress.config.js

import { defineConfig } from 'cypress';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { setupDatabaseDumpHook } from './cypress/db.js';
import { addMatchImageSnapshotPlugin } from '@simonsmith/cypress-image-snapshot/plugin';

export default defineConfig({
    video: false,
    screenshotOnRunFailure: true,
    screenshotsFolder: 'cypress/snapshots',
    trashAssetsBeforeRuns: false,
    viewportWidth: 1920,
    viewportHeight: 1080,
    env: {
        ...JSON.parse(
            fs.readFileSync(
                path.join(path.dirname(fileURLToPath(import.meta.url)), 'cypress', 'cypress.env.json'),
                'utf8'
            )
        )
    },
    e2e: {
        supportFile: 'cypress/support.js',
        specPattern: 'cypress/*.cy.{js,jsx,ts,tsx}',
        experimentalInteractiveRunEvents: true,
        watchForFileChanges: false,
        setupNodeEvents(on, config) {
            setupDatabaseDumpHook(on, config);
            addMatchImageSnapshotPlugin(on, config);
            return config;
        }
    }
});

cypress/...

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment