{
  "doc": {
    "id": "api/node-events/after-run-api",
    "title": "After Run Event | Cypress Node Events",
    "description": "The after:run event fires after a run is finished in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/node-events/after-run-api.md",
    "version": "ce02913654e2655ee63448bdc92bb92c7b46a619",
    "updated_at": "2026-04-22T19:37:51.587Z",
    "headings": [
      {
        "id": "api/node-events/after-run-api#after-run-event",
        "text": "After Run Event",
        "level": 1
      },
      {
        "id": "api/node-events/after-run-api#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/node-events/after-run-api#usage",
        "text": "Usage",
        "level": 2
      },
      {
        "id": "api/node-events/after-run-api#log-the-number-of-passed-tests-of-a-run",
        "text": "Log the number of passed tests of a run",
        "level": 3
      },
      {
        "id": "api/node-events/after-run-api#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "After Run Event"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "The `after:run` event fires after a run is finished. When running cypress via\n`cypress open`, the event will fire when closing a project."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "When running via `cypress run`, the event will fire each time `cypress run`\nexecutes. As a result, if running your specs in\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/cloud/features/smart-orchestration/parallelization.md",
            "children": [
              {
                "type": "text",
                "value": "parallel"
              }
            ]
          },
          {
            "type": "text",
            "value": ", the event will\nfire once for each machine on which `cypress run` is called."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "⚠️ This code is part of the\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/plugins/plugins-guide.md#Using-a-plugin",
            "children": [
              {
                "type": "text",
                "value": "setupNodeEvents"
              }
            ]
          },
          {
            "type": "text",
            "value": " function and\nthus executes in the Node environment. You cannot call `Cypress` or `cy`\ncommands in this function, but you do have the direct access to the file system\nand the rest of the operating system."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "⚠️ When running via `cypress open`, the `after:run` event only fires if the\n"
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/configuration.md#Experiments",
            "children": [
              {
                "type": "text",
                "value": "experimentalInteractiveRunEvents flag"
              }
            ]
          },
          {
            "type": "text",
            "value": "\nis enabled."
          }
        ]
      },
      {
        "type": "code",
        "lang": "ts",
        "meta": null,
        "value": "on('after:run', (results) => {\n  /* ... */\n})"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "results (Object)"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Results of the run, including the total number of passes/failures/etc, the\nproject config, and details about the browser and system. It is the same as the\nresults object resolved by the "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/app/references/module-api.md#Results",
            "children": [
              {
                "type": "text",
                "value": "Module API"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Results are only provided when running via `cypress run`. When running via\n`cypress open`, the results will be undefined."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "You can return a promise from the `after:run` event handler and it will be\nawaited before Cypress proceeds running your specs."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Log the number of passed tests of a run"
          }
        ]
      },
      {
        "type": "code",
        "lang": "ts",
        "meta": null,
        "value": "on('after:run', (results) => {\n  // results will look something like this when run via `cypress run`:\n  // {\n  //   totalDuration: 81,\n  //   totalSuites: 0,\n  //   totalTests: 1,\n  //   totalFailed: 0,\n  //   totalPassed: 1,\n  //   totalPending: 0,\n  //   totalSkipped: 0,\n  //   browserName: 'electron',\n  //   browserVersion: '59.0.3071.115',\n  //   osName: 'darwin',\n  //   osVersion: '16.7.0',\n  //   cypressVersion: '3.1.0',\n  //   config: {\n  //     projectId: '1qv3w7',\n  //     baseUrl: 'http://example.com',\n  //     viewportWidth: 1000,\n  //     viewportHeight: 660,\n  //     // ... more properties...\n  //   }\n  //   // ... more properties...\n  //   }\n  // }\n  if (results) {\n    // results will be undefined in interactive mode\n    console.log(results.totalPassed, 'out of', results.totalTests, 'passed')\n  }\n})"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/node-events/before-run-api.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Before Run API"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/node-events/before-spec-api.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Before Spec API"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/node-events/after-spec-api.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "After Spec API"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/plugins/plugins-guide.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "How to use Plugins"
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/api/node-events/overview.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Node Events Overview"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 471
}