{"id":15552315,"url":"https://github.com/bahmutov/cypress-log-to-term","last_synced_at":"2025-09-28T20:31:10.617Z","repository":{"id":44678769,"uuid":"509501278","full_name":"bahmutov/cypress-log-to-term","owner":"bahmutov","description":"Overwrite the cy.log command to print to both the Command Log and to the terminal","archived":false,"fork":false,"pushed_at":"2024-12-08T18:57:56.000Z","size":572,"stargazers_count":9,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-27T20:52:11.494Z","etag":null,"topics":["cypress-example"],"latest_commit_sha":null,"homepage":"https://cypress.tips/courses/cypress-plugins","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-07-01T15:18:54.000Z","updated_at":"2024-12-12T03:29:47.000Z","dependencies_parsed_at":"2024-06-01T01:35:48.754Z","dependency_job_id":"6ebff51a-621d-4a0e-9c60-aea2a9364099","html_url":"https://github.com/bahmutov/cypress-log-to-term","commit_stats":{"total_commits":29,"total_committers":3,"mean_commits":9.666666666666666,"dds":"0.13793103448275867","last_synced_commit":"18a901a70087ff7993b28089b74a389be354f33a"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-log-to-term","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-log-to-term/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-log-to-term/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-log-to-term/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/cypress-log-to-term/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234558807,"owners_count":18852283,"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":["cypress-example"],"created_at":"2024-10-02T14:15:34.347Z","updated_at":"2025-09-28T20:31:10.611Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cypress-log-to-term ![cypress version](https://img.shields.io/badge/cypress-12.5.1-brightgreen) [![ci](https://github.com/bahmutov/cypress-log-to-term/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/cypress-log-to-term/actions/workflows/ci.yml)\n\n\u003e Overwrite the `cy.log` command to print to both the Command Log and to the terminal\n\n![Logs to both places](./images/log.png)\n\n## Explanation\n\nRead the blog posts \n- [Two Simple Tricks To Make Your Cypress Tests Better](https://glebbahmutov.com/blog/two-cypress-tricks/).\n- [Collect All URLs Visited During Cypress Test](https://glebbahmutov.com/blog/collect-tested-urls/)\n\nThis plugin is covered in my [Cypress Plugins course](https://cypress.tips/courses/cypress-plugins) 🎓:\n- [Lesson a3: Log the messages from the test to the terminal](https://cypress.tips/courses/cypress-plugins/lessons/a3)\n- [Lesson a4: Log the messages using the plugin cypress-log-to-term](https://cypress.tips/courses/cypress-plugins/lessons/a4)\n\n## Install\n\nInstall this plugin from the NPM registry using NPM or Yarn or your favorite Node package manager.\n\n```text\n# Install using NPM\n$ npm i -D cypress-log-to-term\n# Install using Yarn\n$ yarn add -D cypress-log-to-term\n```\n\nInclude the plugin from your support or spec file\n\n```js\n// cypress/e2e/spec.cy.js\n// https://github.com/bahmutov/cypress-log-to-term\nimport 'cypress-log-to-term/commands'\n```\n\nInclude the plugin from your `cypress.config.js` file's `setupNodeEvents` callback\n\n```js\n// cypress.config.js\nconst { defineConfig } = require('cypress')\n\nmodule.exports = defineConfig({\n  e2e: {\n    // baseUrl, etc\n    supportFile: false,\n    fixturesFolder: false,\n    setupNodeEvents(on, config) {\n      // register the \"cypress-log-to-term\" plugin\n      // https://github.com/bahmutov/cypress-log-to-term\n      // IMPORTANT: pass the \"on\" callback argument\n      require('cypress-log-to-term')(on)\n    },\n  },\n})\n```\n\nSee [cypress/e2e/spec.cy.js](./cypress/e2e/spec.cy.js)\n\n## Markdown\n\nMarkdown bold characters `**` are automatically removed before passing them to the task to be printed.\n\n## Yields the current subject\n\nThe `cy.log` yields the current subject to the next command, because [it should](https://glebbahmutov.com/blog/better-cypress-log/).\n\n```js\ncy.wrap(42).log().should('equal', 42)\n```\n\n## Format string\n\nThis plugins adds format string and format callback function feature to the `cy.log` command. For example, the \"standard\" `cy.log` command could only print a string argument\n\n```js\ncy.wrap({ name: 'Joe' }).log('the name')\n// prints \"the name\"\n```\n\nThis module allows you to print the current subject\n\n```js\ncy.wrap({ name: 'Joe' }).log()\n// prints '{\"name\":\"Joe\"}'\n```\n\nComplex objects are supported\n\n```js\ncy.wrap([1, 'hello', { name: 'Joe' }]).log()\n// prints '[1,\"hello\",{\"name\":\"Joe\"}]'\n```\n\nYou can add a string argument and insert the formatted subject into it\n\n```js\ncy.wrap({ name: 'Joe' }).log('person is %o')\n// prints 'person is {\"name\":\"Joe\"}'\n```\n\nThis is equivalent to `{0}` notation\n\n```js\ncy.wrap({ name: 'Joe' }).log('person is {0}')\n// prints 'person is {\"name\":\"Joe\"}'\n```\n\nYou can even access the properties of the subject\n\n```js\ncy.wrap({ name: 'Joe' }).log('my name is {0.name}')\n// prints 'my name is Joe'\n```\n\nDeep properties are allowed\n\n```js\ncy.wrap([{ name: 'Joe' }, { name: { first: 'Anna' } }])\n  // from the subject (accessed via {0})\n  // grab the property \"1\" (which is the second item in our array)\n  // then grab the path \"name.first\"\n  .log('her name is {0.1.name.first}')\n// prints 'her name is Anna'\n```\n\n## Format callback\n\nYou can pass a callback function to the overwritten `cy.log` command. This way you can return a formatted string given the subject value.\n\n```js\nconst person = { name: 'Joe' }\ncy.wrap(person).log((p) =\u003e `name is ${p.name}`)\n// prints 'name is Joe'\ncy.wrap([1, 2, 3]).log((list) =\u003e list[1])\n// prints \"2\"\n```\n\nIf you return non-string result, `cy.log` will try its best to serialize it\n\n```js\ncy.wrap({ name: 'Me' }).log((x) =\u003e x) // {\"name\":\"Me\"}\n```\n\n## Circular objects\n\nIf the subject to be serialized has circular references, they are safely converted to string\n\n```js\nconst obj = {\n  name: 'object',\n}\nobj.next = obj\n// try to log a circular object\ncy.wrap(obj, { log: false }).log()\n// {\"name\":\"object\",\"next\":\"[Circular]\"}\n```\n\nSee [circular.cy.js](./cypress/e2e/circular.cy.js)\n\n## jQuery / DOM elements\n\nAre serialized with main properties (id, class, attributes) and the number of matched elements\n\n```html\n\u003ch1 id=\"title\"\u003eHello\u003c/h1\u003e\n```\n\n```js\ncy.get('h1').log()\n// $ of 1 \u003cdiv#obj.my-object/\u003e\n```\n\nIf there are a lot of yielded elements, only the first and the last one are logged\n\n```html\n\u003col id=\"people\"\u003e\n  \u003cli class=\"first\"\u003eone\u003c/li\u003e\n  \u003cli\u003etwo\u003c/li\u003e\n  \u003cli\u003ethree\u003c/li\u003e\n  \u003cli\u003efour\u003c/li\u003e\n  \u003cli class=\"last\"\u003efive\u003c/li\u003e\n\u003c/ol\u003e\n```\n\n```js\ncy.get('#people li').log()\n// $ of 5 [\u003cli.first/\u003e...\u003cli.last/\u003e]\n```\n\n**Note:** when serializing, the log respects the `chai.config.truncateThreshold` setting. To log more info, increase it in your spec or support file:\n\n```html\n\u003cp class=\"some-class\" data-cy=\"para\" data-test=\"my-p\"\u003eTest page\u003c/p\u003e\n```\n\n```js\ncy.get('#people li').log()\n// default\n// $ of 1 \u003cp.some-class data-cy=para data-t...\n// with chai.config.truncateThreshold = 200\n// $ of 1 \u003cp.some-class data-cy=para data-test=my-p/\u003e\n```\n\n**Tip:** use the format string to better explain what the elements are\n\n```js\ncy.get('#people li').log('list of people %o')\n// list of people $ of 5 [\u003cli.first/\u003e...\u003cli.last/\u003e]\n```\n\nSee [dom.cy.js](./cypress/e2e/dom.cy.js)\n\n## Types\n\nThis package includes TypeScript command definitions for its custom commands in the file [src/index.d.ts](./src/index.d.ts). To use it from your JavaScript specs:\n\n```js\n/// \u003creference types=\"cypress-log-to-term\" /\u003e\n```\n\nIf you are using TypeScript, include this module in your types list\n\n```json\n{\n  \"compilerOptions\": {\n    \"types\": [\"cypress\", \"cypress-log-to-term\"]\n  }\n}\n```\n\n## Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2022\n\n- [@bahmutov](https://twitter.com/bahmutov)\n- [glebbahmutov.com](https://glebbahmutov.com)\n- [blog](https://glebbahmutov.com/blog)\n- [videos](https://www.youtube.com/glebbahmutov)\n- [presentations](https://slides.com/bahmutov)\n- [cypress.tips](https://cypress.tips)\n- [Cypress Tips \u0026 Tricks newsletter](https://cypresstips.substack.com/)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/cypress-log-to-term/issues) on Github\n\n## MIT License\n\nCopyright (c) 2022 Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-log-to-term","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fcypress-log-to-term","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-log-to-term/lists"}