<commit_before>---
title: Before Run API
---

The `before:run` event fires before a run starts. When running cypress via
`cypress open`, the event will fire when opening a project.

The event will fire each time `cypress run` executes. As a result, if running
your specs in [parallel](/guides/guides/parallelization), the event will fire
once for each machine on which the tests are run.

## Syntax

::include{file=partials/warning-setup-node-events.md}

<Alert type="warning">

⚠️ When running via `cypress open`, the `before:run` event only fires if the
[experimentalInteractiveRunEvents flag](/guides/references/configuration#Experiments)
is enabled.

</Alert>

:::cypress-plugin-example

```js
on('before:run', (details) => {
  /* ... */
})
```

:::

**<Icon name="angle-right"></Icon> details** **_(Object)_**

Details of the run, including the project config, system information, and the
version of Cypress. More details are included when running via `cypress run`.

## Usage

You can return a promise from the `before:run` event handler and it will be
awaited before Cypress proceeds running your specs.

### Log the browser and the number of specs that will be run

```javascript
module.exports = (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_spec.js',
    //       relative: 'cypress/integration/login_spec.js',
    //       absolute: '/Users/janelane/app/cypress/integration/login_spec.js',
    //     },
    //     // ... more specs
    //   ],
    //   specPattern: [
    //     '**/*_spec.js'
    //   ],
    //   parallel: false,
    //   group: 'group-1',
    //   tag: 'tag-1'
    // }<commit_msg>update specPattern log example<commit_after>---
title: Before Run API
---

The `before:run` event fires before a run starts. When running cypress via
`cypress open`, the event will fire when opening a project.

The event will fire each time `cypress run` executes. As a result, if running
your specs in [parallel](/guides/guides/parallelization), the event will fire
once for each machine on which the tests are run.

## Syntax

::include{file=partials/warning-setup-node-events.md}

<Alert type="warning">

⚠️ When running via `cypress open`, the `before:run` event only fires if the
[experimentalInteractiveRunEvents flag](/guides/references/configuration#Experiments)
is enabled.

</Alert>

:::cypress-plugin-example

```js
on('before:run', (details) => {
  /* ... */
})
```

:::

**<Icon name="angle-right"></Icon> details** **_(Object)_**

Details of the run, including the project config, system information, and the
version of Cypress. More details are included when running via `cypress run`.

## Usage

You can return a promise from the `before:run` event handler and it will be
awaited before Cypress proceeds running your specs.

### Log the browser and the number of specs that will be run

```javascript
module.exports = (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_spec.js',
    //       relative: 'cypress/integration/login_spec.js',
    //       absolute: '/Users/janelane/app/cypress/integration/login_spec.js',
    //     },
    //     // ... more specs
    //   ],
    //   specPattern: [
    //     '**/*.cy.{js,jsx,ts,tsx}'
    //   ],
    //   parallel: false,
    //   group: 'group-1',
    //   tag: 'tag-1'
    // }
{'fraction_non_alphanumeric': 0.1614490161001789, 'fraction_numerical': 0.013864042933810376, 'mean_word_length': 2.262582056892779, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4769114', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1415, 'n_words': 415}