---
id: api/node-events/after-run-api
title: 'after:run event'
description: 'The after:run event fires after a run is finished in Cypress.'
section: api
source_path: docs/api/node-events/after-run-api.mdx
version: 29f95bf8bb06f320986f3749f5bf09a35a409eab
updated_at: '2026-09-04T10:49:54.630Z'
---
# After Run Event

The `after:run` event fires after a run is finished. When running cypress via `cypress open`, the event will fire when closing a project.

When running via `cypress run`, the event will fire each time `cypress run` executes. As a result, if running your specs in [parallel](/llm/markdown/cloud/features/smart-orchestration/parallelization.md), the event will fire once for each machine on which `cypress run` is called.

## Syntax

⚠️ 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.

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

*   cypress.config.js
*   cypress.config.ts

```
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('after:run', (results) => {
        /* ... */
      })
    },
  },
})
```

```
import { defineConfig } from 'cypress'

export default defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('after:run', (results) => {
        /* ... */
      })
    },
  },
})
```

**results _(Object)_**

Results of the run, including the total number of passes/failures/etc, the project config, and details about the browser and system. It is the same as the results object resolved by the [Module API](/llm/markdown/app/references/module-api.md#Results).

Results are only provided when running via `cypress run`. When running via `cypress open`, the results will be undefined.

## Usage

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

### Log the number of passed tests of a run

*   cypress.config.js
*   cypress.config.ts

```
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('after:run', (results) => {
        // results will look something like this when run via `cypress run`:
        // {
        //   totalDuration: 81,
        //   totalSuites: 0,
        //   totalTests: 1,
        //   totalFailed: 0,
        //   totalPassed: 1,
        //   totalPending: 0,
        //   totalSkipped: 0,
        //   browserName: 'electron',
        //   browserVersion: '59.0.3071.115',
        //   osName: 'darwin',
        //   osVersion: '16.7.0',
        //   cypressVersion: '3.1.0',
        //   config: {
        //     projectId: '1qv3w7',
        //     baseUrl: 'http://example.com',
        //     viewportWidth: 1000,
        //     viewportHeight: 660,
        //     // ... more properties...
        //   }
        //   // ... more properties...
        //   }
        // }
        if (results) {
          // results will be undefined in interactive mode
          console.log(
            results.totalPassed,
            'out of',
            results.totalTests,
            'passed'
          )
        }
      })
    },
  },
})
```

```
import { defineConfig } from 'cypress'

export default defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('after:run', (results) => {
        // results will look something like this when run via `cypress run`:
        // {
        //   totalDuration: 81,
        //   totalSuites: 0,
        //   totalTests: 1,
        //   totalFailed: 0,
        //   totalPassed: 1,
        //   totalPending: 0,
        //   totalSkipped: 0,
        //   browserName: 'electron',
        //   browserVersion: '59.0.3071.115',
        //   osName: 'darwin',
        //   osVersion: '16.7.0',
        //   cypressVersion: '3.1.0',
        //   config: {
        //     projectId: '1qv3w7',
        //     baseUrl: 'http://example.com',
        //     viewportWidth: 1000,
        //     viewportHeight: 660,
        //     // ... more properties...
        //   }
        //   // ... more properties...
        //   }
        // }
        if (results) {
          // results will be undefined in interactive mode
          console.log(
            results.totalPassed,
            'out of',
            results.totalTests,
            'passed'
          )
        }
      })
    },
  },
})
```

## See also

*   [Before Run API](/llm/markdown/api/node-events/before-run-api.md)
*   [Before Spec API](/llm/markdown/api/node-events/before-spec-api.md)
*   [After Spec API](/llm/markdown/api/node-events/after-spec-api.md)
*   [How to use Plugins](/llm/markdown/app/plugins/plugins-guide.md)
*   [Node Events Overview](/llm/markdown/api/node-events/overview.md)
