{
  "doc": {
    "id": "api/node-events/before-run-api",
    "title": "Before Run Event | Cypress Node Events",
    "description": "The before:run event fires before a run starts in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/node-events/before-run-api.md",
    "version": "e6988a974973e9090ce70406c38cb2b9e0eac9fa",
    "updated_at": "2026-05-15T15:50:22.536Z",
    "headings": [
      {
        "id": "api/node-events/before-run-api#before-run-event",
        "text": "Before Run Event",
        "level": 1
      },
      {
        "id": "api/node-events/before-run-api#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/node-events/before-run-api#usage",
        "text": "Usage",
        "level": 2
      },
      {
        "id": "api/node-events/before-run-api#log-the-browser-and-the-number-of-specs-that-will-be-run",
        "text": "Log the browser and the number of specs that will be run",
        "level": 3
      },
      {
        "id": "api/node-events/before-run-api#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/node-events/before-run-api#syntax",
      "doc_id": "api/node-events/before-run-api",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n⚠️ This code is part of the [setupNodeEvents](/llm/markdown/app/plugins/plugins-guide.md#Using-a-plugin) function and thus executes in the Node environment. You cannot call `Cypress` or `cy` commands in this function, but you do have the direct access to the file system and the rest of the operating system.\n\n⚠️ When running via `cypress open`, the `before:run` event only fires if the [experimentalInteractiveRunEvents flag](/llm/markdown/app/references/experiments.md#Configuration) is enabled.\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      on('before:run', (details) => {        /* ... */      })    },  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      on('before:run', (details) => {        /* ... */      })    },  },})\n```\n\n**details _(Object)_**\n\nDetails of the run, including the project config, system information, and the version of Cypress. More details are included when running via `cypress run`.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/node-events/before-run-api.json",
      "token_estimate": 225
    },
    {
      "id": "api/node-events/before-run-api#usage",
      "doc_id": "api/node-events/before-run-api",
      "heading": "Usage",
      "heading_level": 2,
      "content_markdown": "## Usage\n\nYou can return a promise from the `before:run` event handler and it will be awaited before Cypress proceeds running your specs.\n\n### Log the browser and the number of specs that will be run\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      on('before:run', (details) => {        // details will look something like this when run via `cypress run`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   browser: {        //     name: 'electron',        //     version: '59.0.3071.115',        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '6.1.0',        //   specs: [        //     {        //       name: 'login_cy.js',        //       relative: 'cypress/e2e/login_cy.js',        //       absolute: '/Users/janelane/app/cypress/e2e/login_cy.js',        //     },        //     // ... more specs        //   ],        //   specPattern: [        //     '**/*.cy.{js,jsx,ts,tsx}'        //   ],        //   parallel: false,        //   group: 'group-1',        //   tag: 'tag-1'        // }        // details will look something like this when run via `cypress open`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '7.0.0'        // }        if (details.specs && details.browser) {          // details.specs and details.browser will be undefined in interactive mode          console.log(            'Running',            details.specs.length,            'specs in',            details.browser.name          )        }      })    },  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      on('before:run', (details) => {        // details will look something like this when run via `cypress run`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   browser: {        //     name: 'electron',        //     version: '59.0.3071.115',        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '6.1.0',        //   specs: [        //     {        //       name: 'login_cy.js',        //       relative: 'cypress/e2e/login_cy.js',        //       absolute: '/Users/janelane/app/cypress/e2e/login_cy.js',        //     },        //     // ... more specs        //   ],        //   specPattern: [        //     '**/*.cy.{js,jsx,ts,tsx}'        //   ],        //   parallel: false,        //   group: 'group-1',        //   tag: 'tag-1'        // }        // details will look something like this when run via `cypress open`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '7.0.0'        // }        if (details.specs && details.browser) {          // details.specs and details.browser will be undefined in interactive mode          console.log(            'Running',            details.specs.length,            'specs in',            details.browser.name          )        }      })    },  },})\n```\n",
      "section": "api",
      "anchors": [
        "usage"
      ],
      "path": "/llm/json/chunked/api/node-events/before-run-api.json",
      "token_estimate": 624
    },
    {
      "id": "api/node-events/before-run-api#log-the-browser-and-the-number-of-specs-that-will-be-run",
      "doc_id": "api/node-events/before-run-api",
      "heading": "Log the browser and the number of specs that will be run",
      "heading_level": 3,
      "content_markdown": "### Log the browser and the number of specs that will be run\n\n*   cypress.config.js\n*   cypress.config.ts\n\n```\nconst { defineConfig } = require('cypress')module.exports = defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      on('before:run', (details) => {        // details will look something like this when run via `cypress run`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   browser: {        //     name: 'electron',        //     version: '59.0.3071.115',        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '6.1.0',        //   specs: [        //     {        //       name: 'login_cy.js',        //       relative: 'cypress/e2e/login_cy.js',        //       absolute: '/Users/janelane/app/cypress/e2e/login_cy.js',        //     },        //     // ... more specs        //   ],        //   specPattern: [        //     '**/*.cy.{js,jsx,ts,tsx}'        //   ],        //   parallel: false,        //   group: 'group-1',        //   tag: 'tag-1'        // }        // details will look something like this when run via `cypress open`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '7.0.0'        // }        if (details.specs && details.browser) {          // details.specs and details.browser will be undefined in interactive mode          console.log(            'Running',            details.specs.length,            'specs in',            details.browser.name          )        }      })    },  },})\n```\n\n```\nimport { defineConfig } from 'cypress'export default defineConfig({  // setupNodeEvents can be defined in either  // the e2e or component configuration  e2e: {    setupNodeEvents(on, config) {      on('before:run', (details) => {        // details will look something like this when run via `cypress run`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   browser: {        //     name: 'electron',        //     version: '59.0.3071.115',        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '6.1.0',        //   specs: [        //     {        //       name: 'login_cy.js',        //       relative: 'cypress/e2e/login_cy.js',        //       absolute: '/Users/janelane/app/cypress/e2e/login_cy.js',        //     },        //     // ... more specs        //   ],        //   specPattern: [        //     '**/*.cy.{js,jsx,ts,tsx}'        //   ],        //   parallel: false,        //   group: 'group-1',        //   tag: 'tag-1'        // }        // details will look something like this when run via `cypress open`:        // {        //   config: {        //     projectId: '12345',        //     baseUrl: 'http://example.com/',        //     viewportWidth: 1000,        //     viewportHeight: 660,        //     // ...more properties...        //   },        //   system: {        //     osName: 'darwin',        //     osVersion: '16.7.0',        //   }        //   cypressVersion: '7.0.0'        // }        if (details.specs && details.browser) {          // details.specs and details.browser will be undefined in interactive mode          console.log(            'Running',            details.specs.length,            'specs in',            details.browser.name          )        }      })    },  },})\n```\n",
      "section": "api",
      "anchors": [
        "log-the-browser-and-the-number-of-specs-that-will-be-run"
      ],
      "path": "/llm/json/chunked/api/node-events/before-run-api.json",
      "token_estimate": 593
    }
  ]
}