Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ If your using TypeScript with Cypress, you can add type in your `tsconfig.json`

[all-logs]: https://github.com/bahmutov/all-logs

## Development

- install all dependencies using `npm install`
- start watching and compiling the TS source using `npm run build:watch`
- from another terminal launch the local server and open Cypress using `npm run dev`
- open the desired Cypress spec file

### Small print

Author: Gleb Bahmutov <[email protected]> © 2019
Expand Down
43 changes: 43 additions & 0 deletions cypress/e2e/server-logs.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// loads definition for the custom "cy.api" command
/// <reference path="../../dist/types.d.ts" />

it('shows the full message from the server logs', () => {
cy.api({
method: 'POST',
url: '/json',
body: {
name: 'Jane',
},
})
.its('messages')
.should('be.an', 'array')
.map('message')
.should('deep.equal', ['POST /json', { name: 'Jane' }])

cy.get('.cy-api-logs-messages').should('not.include.text', '[object Object]')
cy.get('.cy-api-logs-messages')
.find('.console.console-log')
.should('read', ['console log: POST /json', 'console log: {"name":"Jane"}'])
})

it('serializes multiple arguments', () => {
cy.api(
{
url: '/sum',
body: {
a: 10,
b: -5,
},
},
'sum',
)
.its('body.sum')
.should('equal', 5)

cy.get('.cy-api-logs-messages')
.find('.console.console-log')
.should('read', [
'console log: summing { a: 10, b: -5 }',
'console log: returning sum 5',
])
})
3 changes: 3 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// add cypress-map commands and queries
import 'cypress-map'

// adds cy.api command
import '../../dist/support'
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@bahmutov/all-logs": "1.8.1",
"@types/node": "^17.0.18",
"cypress": "13.16.0",
"cypress-map": "^1.43.0",
"debug": "4.4.0",
"express": "4.17.1",
"husky": "3.1.0",
Expand Down
18 changes: 11 additions & 7 deletions src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,17 @@ const printResponse = (
container.innerHTML +=
'\n<pre class="cy-api-logs-messages">' +
messages
.map(
(m) =>
`<div class="${normalize(m.type)} ${normalize(
m.type,
m.namespace,
)}">${m.type} ${m.namespace}: ${m.message}</div>`,
)
.map((m) => {
const s =
typeof m.message === 'string'
? m.message
: JSON.stringify(m.message)
const html = `<div class="${normalize(m.type)} ${normalize(
m.type,
m.namespace,
)}">${m.type} ${m.namespace}: ${s}</div>`
return html
})
.join('') +
'\n</pre></div>'
}
Expand Down