{"id":13492790,"url":"https://github.com/archfz/cypress-terminal-report","last_synced_at":"2025-05-14T05:10:30.219Z","repository":{"id":38335599,"uuid":"235415674","full_name":"archfz/cypress-terminal-report","owner":"archfz","description":"Plugin for cypress. Logs to terminal and files, mimicking cypress UI.","archived":false,"fork":false,"pushed_at":"2025-05-09T21:03:13.000Z","size":2382,"stargazers_count":516,"open_issues_count":8,"forks_count":37,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-12T07:51:31.017Z","etag":null,"topics":["ci","cli","console","cypress","hacktoberfest","log","output","pretty","print","terminal"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/archfz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-21T18:44:53.000Z","updated_at":"2025-05-09T21:03:17.000Z","dependencies_parsed_at":"2023-09-28T18:45:18.132Z","dependency_job_id":"60d1741a-f620-4e0e-bdbb-55dd7b7da80c","html_url":"https://github.com/archfz/cypress-terminal-report","commit_stats":{"total_commits":466,"total_committers":25,"mean_commits":18.64,"dds":0.5,"last_synced_commit":"ee42c064a082a4462eaeff945951b55eeb005db0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archfz%2Fcypress-terminal-report","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archfz%2Fcypress-terminal-report/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archfz%2Fcypress-terminal-report/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archfz%2Fcypress-terminal-report/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archfz","download_url":"https://codeload.github.com/archfz/cypress-terminal-report/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076848,"owners_count":22010611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci","cli","console","cypress","hacktoberfest","log","output","pretty","print","terminal"],"created_at":"2024-07-31T19:01:09.217Z","updated_at":"2025-05-14T05:10:30.186Z","avatar_url":"https://github.com/archfz.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Uncategorized","JavaScript"],"sub_categories":["Uncategorized"],"readme":"# Cypress terminal report [![Build Status](https://circleci.com/gh/archfz/cypress-terminal-report/tree/master.svg?style=svg)](https://app.circleci.com/pipelines/github/archfz/cypress-terminal-report) [![Downloads](https://badgen.net/npm/dw/cypress-terminal-report)](https://www.npmjs.com/package/cypress-terminal-report) [![Version](https://badgen.net/npm/v/cypress-terminal-report)](https://www.npmjs.com/package/cypress-terminal-report)\n\n\u003e This documentation is for cypress \u003e= 12.0.0. For older versions see [4.x.x](https://github.com/archfz/cypress-terminal-report/tree/4.x.x) or [3.x.x branch](https://github.com/archfz/cypress-terminal-report/tree/3.x.x).\n\n\u003cdiv align=\"center\"\u003e\n\n[Limitations](#limitations-and-notes)\n• [Install](#install)\n• [Options](#options)\n• [Integrations](#integrations)\n• [After/before all](#logging-after-all-and-before-all-hooks)\n• [Logging to files](#logging-to-files)\n• [Development](#development)\n• [Release Notes](./RELEASE_NOTES.md)\n\n\u003c/div\u003e\n\nPlugin for cypress that adds better terminal output for easier debugging.\nPrints cy commands, browser console logs, cy.request and cy.intercept data. Great for your pipelines.\n\n- looks pretty in console\n- logs all commands, requests and browser console logs\n- supports logging to files\n- option between logging only on failure (default) or always\n- options for trimming and compacting logs\n- support for multiple and nested mocha contexts\n- log commands from before all and after all hooks ([with a catch\\*](#logging-after-all-and-before-all-hooks))\n\nTry it out by cloning [cypress-terminal-report-demo](https://github.com/archfz/cypress-terminal-report-demo).\n\n![demo](https://raw.githubusercontent.com/archfz/cypress-terminal-report/master/demo.png?sanitize=true#gh-light-mode-only)\n![demo](https://raw.githubusercontent.com/archfz/cypress-terminal-report/master/demo_dark.png?sanitize=true#gh-dark-mode-only)\n\n## Limitations and notes\n\n- By default logs are not printed for successful tests. Please see [option](#optionsprintlogstoconsole) to change this.\n- `console.log` usage was never meant to be used in the cypress test code. Using it will\n  not log anything with this plugin. Using it also goes against the queue nature of\n  cypress. Use `cy.log` instead. [See here for more details](https://github.com/archfz/cypress-terminal-report/issues/67).\n\n## Install\n\n### Requirements\n\n- `\u003e=4.0.0` requires cypress `\u003e=10.0.0` and node `\u003e=12`\n- `\u003e=3.0.0` requires cypress `\u003e=4.10.0`\n- `\u003c3.0.0` requires cypress `\u003e=3.8.0`\n\n1. Install npm package.\n   ```bash\n   npm i --save-dev cypress-terminal-report\n   ```\n2. If using typescript and es6 imports ensure `esModuleInterop` is enabled.\n3. Register the output plugin in `cypress.config.{js|ts}`\n   ```js\n   module.exports = defineConfig({\n     e2e: {\n       setupNodeEvents(on, config) {\n         require('cypress-terminal-report/src/installLogsPrinter')(on)\n       }\n     }\n   })\n   ```\n4. Register the log collector support in `cypress/support/e2e.{js|ts}`\n   ```js\n   require('cypress-terminal-report/src/installLogsCollector')()\n   ```\n\n## Options\n\n\u003cbr/\u003e\n\n### _Options for the plugin install_\n\n\u003e require('cypress-terminal-report/src/installLogsPrinter')(on, options)\n\n#### `options.defaultTrimLength`\n\ninteger; default: 800; Max length of cy.log and console.warn/console.error.\n\n#### `options.commandTrimLength`\n\ninteger; default: 800; Max length of cy commands.\n\n#### `options.routeTrimLength`\n\ninteger; default: 5000; Max length cy.request and XHR data.\n\n#### `options.compactLogs`\n\ninteger?; default: null; If it is set to a number greater or equal to 0, this amount of logs\nwill be printed only around failing commands. Use this to have shorter output especially\nfor when there are a lot of commands in tests. When used with `options.printLogsToConsole=always`\nfor tests that don't have any `severity=error` logs nothing will be printed.\n\n#### `options.outputCompactLogs`\n\ninteger? | false; default: null; Overrides `options.compactLogs` for the file log output specifically,\nwhen `options.outputTarget` is specified. Allows compacting of the terminal and the file output logs to different levels.  \nIf `options.outputCompactLogs` is unspecified, file output will use `options.compactLogs`.\nIf set to `false`, output file logs will not compact even if `options.compactLogs` is set.\n\n#### `options.outputRoot`\n\nstring; default: null; Required if `options.outputTarget` provided. [More details](#logging-to-files).\n\n#### `options.specRoot`\n\nstring; default: null; Cypress specs root relative to package json. [More details](#log-specs-in-separate-files).\n\n#### `options.outputTarget`\n\nobject; default: null; Output logs to files. [More details](#logging-to-files).\n\n#### `options.printLogsToConsole`\n\nstring; Default: 'onFail'. When to print logs to console, possible values: 'always', 'onFail', 'never' - When set to always\nlogs will be printed to console for successful tests as well as failing ones.\n\n#### `options.printLogsToFile`\n\nstring; Default: 'onFail'. When to print logs to file(s), possible values: 'always', 'onFail', 'never' - When set to always\nlogs will be printed to file(s) for successful tests as well as failing ones.\n\n#### `options.includeSuccessfulHookLogs`\n\nboolean; Default: false. Commands from before all and after all hooks by default get logged only if\na command from them failed. This default is in accordance with the defaults on `options.printLogsTo*` to\navoid printing too many, possibly irrelevant, information. However you can set this to `true` if you\nneed more extensive logging, but be aware that commands will be logged to terminal from these hooks\nregardless whether there were failing tests in the suite. This is because we can't know for sure in\nadvanced if a test fails or not.\n\n#### `options.outputVerbose`\n\nboolean; default: true; Toggles verbose output. Currently just writes out additional file write information, if any.\n\n#### `options.debug`\n\nboolean; default: false; Toggles debug output. Useful in cases of difficult to reproduce issues with the plugin.\n\n#### `options.collectTestLogs` \\*1\n\n([spec, test, state], {type, message, severity}[]) =\u003e void; default: undefined;\nCallback to collect each test case's logs after its run.\nThe first argument contains information about the test: the `spec` (test file), `test` (test title) and `state` (test state) fields.\nThe second argument contains the test logs. 'type' is from the same list as for the `collectTypes` support install option (see below). Severity can be of ['', 'error', 'warning'].\n\n#### `options.logToFilesOnAfterRun`\n\nboolean; default: false;\nWhen set to true it enables additional log write pass to files using the cypress [`after:run`](https://docs.cypress.io/api/plugins/after-run-api) plugin\nhook. This option can only be used with cypress 6.2.0 onwards, and with the additional\n`experimentalRunEvents` configuration on versions smaller than 6.7.0.\n\n\u003cbr/\u003e\n\n### _Options for the support install_\n\n\u003e require('cypress-terminal-report/src/installLogsCollector')(options);\n\n#### `options.collectTypes`\n\narray; default: ['cons:log','cons:info', 'cons:warn', 'cons:error', 'cy:log', 'cy:xhr', 'cy:request', 'cy:intercept', 'cy:command']\nWhat types of logs to collect and print. By default all types are enabled. The 'cy:command' is the general type that\ncontain all types of commands that are not specially treated.\n\n#### `options.commandTimings`\n\nnull | 'timestamp' | 'seconds'; default: null;\nRecord and log the time when the logs were generated.\n'timestamp' is the epoch timestamp in milliseconds.\n'seconds' is the number of seconds since the test start, displaying the milliseconds as decimals.\n\n#### `options.filterLog`\n\nnull | ({type, message, severity}) =\u003e boolean; default: undefined;\nCallback to filter logs manually.\nThe type is from the same list as for the `collectTypes` option. Severity can be of ['', 'error', 'warning'].\n\n#### `options.processLog`\n\nnull | ({type, message, severity}) =\u003e {type, message, severity}; default: undefined;\nCallback to process logs manually.\nThe type is from the same list as for the `collectTypes` option. Severity can be of ['', 'error', 'warning'].\n\n#### `options.collectTestLogs` \\*2\n\n(mochaRunnable, {type, message, severity}[]) =\u003e void; default: undefined;\nCallback to collect each test case's logs after its run.\nThe `mochaRunnable` is of type `Test | Hook` from the mocha library.\nThe type is from the same list as for the `collectTypes` option. Severity can be of ['', 'error', 'warning'].\n\n#### `options.xhr.printBody`\n\nboolean; default true; Whether to print response data. Controls request body as well when `printRequestData` is\nenabled. Note that currently response body is logged only on failing requests and when this config is enabled.\n\n#### `options.xhr.printHeaderData`\n\nboolean; default false; Whether to print header data for XHR requests.\n\n#### `options.xhr.printRequestData`\n\nboolean; default false; Whether to print request data for XHR requests besides response data.\n\n#### `options.enableExtendedCollector`\n\nboolean; default false; Enables an extended collector which will also collect command logs from\nbefore all and after all hooks.\n\n#### `options.enableContinuousLogging`\n\nboolean; default false; Enables logging logs to terminal continuously / immediately as they are registered.\nThis feature is unstable and has an impact on pipeline performance. This option has no effect for extended\ncollector, only works for the simple collector. Use only for debugging purposes in case the pipelines /\ntests are timing out.\n\n\u003e NOTE: In case of this option enabled, logs will come before the actual title of the test. Also the\n\u003e `printLogsToConsole` option will be ignored. Logging to files might also get impacted.\n\n#### _Example for options for the support install_\n\n```js\n// ...\n// Options for log collector\nconst options = {\n  // Log console output only\n  collectTypes: ['cons:log', 'cons:info', 'cons:warn', 'cons:error']\n}\n\n// Register the log collector\nrequire('cypress-terminal-report/src/installLogsCollector')(options)\n// ...\n```\n\n## Integrations\n\n### `cypress-fail-fast`\n\nLogging to files does not work out of the box. To enable support use the\n[`logToFilesOnAfterRun`](#optionslogtofilesonafterrun) option.\n\n### `cypress-mochawesome-reporter`\n\nThe following example demonstrates adding logs to context for all tests (snippet from `e2e.js`):\n\n```js\nimport 'cypress-mochawesome-reporter/register'\n\nafterEach(() =\u003e {\n  cy.wait(50, {log: false}).then(() =\u003e cy.addTestContext(Cypress.TerminalReport.getLogs('txt')))\n})\n\n// Ensure that after plugin installation is after the afterEach handling the integration.\nrequire('cypress-terminal-report/src/installLogsCollector')()\n```\n\nFor typescript support add to your tsconfig **types** `cypress-terminal-report`.\n\n## Logging after all and before all hooks\n\nCommands from before all and after all hooks are not logged by default. A new experimental feature introduces\nsupport for logging commands from these hooks: [`enableExtendedCollector`](#optionsenableextendedcollector).\nThis feature is by default disabled as it relies much more heavily on internals of cypress and\nmocha, thus **there is a higher chance of something breaking, especially with cypress upgrades**.\n\nOnce the feature enabled, logs from these hooks will only appear in console if:\n\n- a command from the hook fails\n- hook passes and [`printLogsToConsole`](#optionsprintlogstoconsole) == `always`\n- hook passes and [`printLogsToConsole`](#optionsprintlogstoconsole) ==`onFail`\n  and [`includeSuccessfulHookLogs`](#optionsprintlogstoconsole) == `true`\n\nGlobal `after all` hooks need to be registered before the registration of the `support install`, otherwise\nthey will not be added to file outputs, if such is configured. Example `e2e.js`:\n\n```js\nafter(() =\u003e cy.log('this log will appear in the output files'))\nrequire('cypress-terminal-report/src/installLogsCollector')(config)\nafter(() =\u003e cy.log('this log will NOT appear in the files'))\n```\n\n## Logging to files\n\nTo enable logging to file you must add the following configuration options to the\nplugin install.\n\n```js\nsetupNodeEvents(on, config) {\n  // ...\n  const options = {\n    outputRoot: config.projectRoot + '/logs/',\n    outputTarget: {\n      'out.txt': 'txt',\n      'out.json': 'json',\n      'out.html': 'html',\n    }\n  };\n\n  require('cypress-terminal-report/src/installLogsPrinter')(on, options);\n  // ...\n}\n```\n\nThe `outputTarget` needs to be an object where the key is the relative path of the\nfile from `outputRoot` and the value is the **type** of format to output.\n\nSupported types: `txt`, `json`, `html`.\n\n### Log specs in separate files\n\nTo create log output files per spec file instead of one single file change the\nkey in the `outputTarget` to the format `{directory}|{extension}`, where\n`{directory}` the root directory where to generate the files and `{extension}`\nis the file extension for the log files. The generated output will have the\nsame structure as in the cypress specs root directory.\n\n```js\nsetupNodeEvents(on, config) {\n  const options = {\n    outputRoot: config.projectRoot + '/logs/',\n    // Used to trim the base path of specs and reduce nesting in the generated output directory.\n    specRoot: 'cypress/e2e',\n    outputTarget: {\n      'cypress-logs|json': 'json',\n    }\n  };\n}\n```\n\n### Custom output log processor\n\nIf you need to output in a custom format you can pass a function instead of a string\nto the `outputTarget` value. This function will be called with the list of messages\nper spec per test. It is called right after one spec finishes, which means on each\niteration it will receive for one spec the messages. See for example below.\n\n\u003e NOTE: The chunks have to be written in a way that after every write the file is\n\u003e in a valid format. This has to be like this since we cannot detect when cypress\n\u003e runs the last test. This way we also make the process faster because otherwise the\n\u003e more tests would execute the more RAM and processor time it would take to rewrite\n\u003e all the logs to the file.\n\nInside the function you will have access to the following API:\n\n- `this.size` - Current char size of the output file.\n- `this.atChunk` - The count of the chunk to be written.\n- `this.initialContent` - The initial content of the file. Defaults to `''`. Set this\n  before the first chunk write in order for it to work.\n- `this.chunkSeparator` - Chunk separator string. Defaults to `''`. This string will\n  be written between each chunk. If you need a special separator between chunks use this\n  as it is internally handled to properly write and replace the chunks.\n- `this.writeSpecChunk(specPath, dataString, positionInFile?)` - Writes a chunk of\n  data in the output file.\n\n```js\n// ...\nconst options = {\n  outputTarget: {\n    'custom.output': function (allMessages, options) {\n      // allMessages= {[specPath: string]: {[testTitle: string]: [type: string, message: string, severity: string][]}}\n\n      Object.entries(allMessages).forEach(([spec, tests]) =\u003e {\n        let text = `${spec}:\\n`\n        Object.entries(tests).forEach(([test, messages]) =\u003e {\n          text += `    ${test}\\n`\n          messages.forEach(({type, message, severity}) =\u003e {\n            text += `        ${type} (${severity}): ${message}\\n`\n          })\n        })\n\n        // .. Process the tests object into desired format ..\n        // Insert chunk into file, by default at the end.\n        this.writeSpecChunk(spec, text)\n        // Or before the last two characters.\n        this.writeSpecChunk(spec, text, -2)\n      })\n    }\n  }\n}\n// ...\n```\n\nSee [JsonOutputProcessor](./src/outputProcessor/JsonOutputProcessor.js) implementation as a\ngood example demonstrating both conversion of data into string and chunk write position\nalternation.\n\n### HTML output log processor\n\nThe HTML output processor has default styles:\n\n```css\nbody {\n  font-family: monospace;\n}\np {\n  margin: 0;\n  padding: 0;\n}\npre {\n  display: inline;\n  margin: 0;\n}\nh2 {\n  margin: 0;\n  font-size: 1.2em;\n}\n```\n\nTo pass custom CSS styles:\n\n```js\nconst HtmlOutputProcessor = require('cypress-terminal-report/src/outputProcessor/HtmlOutputProcessor')\n// ...\nsetupNodeEvents(on, config) {\n  const options = {\n    // ...\n    outputTarget: {\n      'html': function (this) {\n        return new HtmlOutputProcessor(\n          this.file,\n          this.options,\n          `\n          /* Custom CSS */\n          `\n        )\n      },\n  };\n}\n```\n\n## Development\n\n### Testing\n\nTests can be found under `/test`. The primary expectations are run with mocha and these tests in fact\nstart cypress run instances and assert on their output. So that means there is a cypress suite that\nis used to emulate the usage of the plugin, and a mocha suite to assert on those emulations.\n\nTo add tests you need to first add a case to existing cypress spec or create a new one and then\nadd the case as well in the `/test/test.js`. To run the tests you can use `npm test` in the test \\\ndirectory. You should add `it.only` to the test case you are working on to speed up development.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchfz%2Fcypress-terminal-report","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchfz%2Fcypress-terminal-report","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchfz%2Fcypress-terminal-report/lists"}