Skip to content

Commit df2b0ca

Browse files
committed
feat: better visual style for logs, close #14
1 parent c860ce8 commit df2b0ca

3 files changed

Lines changed: 38 additions & 9 deletions

File tree

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
"peerDependencies": {
4747
"cypress": "3"
4848
},
49-
"dependencies": {},
49+
"dependencies": {
50+
"common-tags": "1.8.0"
51+
},
5052
"publishConfig": {
5153
"access": "public"
5254
},

support.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
/// <reference types="cypress" />
22

3+
import { html } from 'common-tags'
4+
5+
//
6+
// implementation of the custom command "cy.api"
7+
// https://github.com/bahmutov/cy-api
8+
//
9+
310
// shortcuts to a few Lodash methods
411
const { get, filter, map, uniq } = Cypress._
512

@@ -42,19 +49,40 @@ Cypress.Commands.add('api', (options, name = 'api') => {
4249
let topMargin
4350
if (firstApiRequest) {
4451
// remove existing content from the application frame
45-
container.innerHTML = ''
4652
firstApiRequest = false
4753
topMargin = '0'
54+
container.innerHTML = html`
55+
<style>
56+
.cy-api {
57+
text-align: left;
58+
}
59+
.cy-api-request {
60+
font-weight: 600;
61+
}
62+
.cy-api-logs-messages {
63+
text-align: left;
64+
max-height: 25em;
65+
overflow-y: scroll;
66+
background-color: lightyellow;
67+
padding: 4px;
68+
border-radius: 4px;
69+
}
70+
.cy-api-response {
71+
text-align: left;
72+
margin-top: 1em;
73+
}
74+
</style>
75+
`
4876
} else {
4977
container.innerHTML += '<br><hr>\n'
5078
topMargin = '1em'
5179
}
5280

5381
container.innerHTML +=
5482
// should we use custom class and insert class style?
55-
'<div style="">\n' +
56-
`<h1 style="text-align: left; margin: ${topMargin} 0 1em; font-weight: 600">Cy-api: ${name}</h1>\n` +
57-
'<div style="text-align: left">\n' +
83+
'<div class="cy-api">\n' +
84+
`<h1 class="cy-api-request" style="margin: ${topMargin} 0 1em">Cy-api: ${name}</h1>\n` +
85+
'<div>\n' +
5886
'<b>Request:</b>\n' +
5987
'<pre>' +
6088
JSON.stringify(options, null, 2) +
@@ -122,7 +150,7 @@ Cypress.Commands.add('api', (options, name = 'api') => {
122150
}
123151

124152
container.innerHTML +=
125-
'\n<pre style="text-align: left; max-height: 25em; overflow-y: scroll;">' +
153+
'\n<pre class="cy-api-logs-messages">' +
126154
messages
127155
.map(m => `${m.type} ${m.namespace}: ${m.message}`)
128156
.join('<br/>') +
@@ -132,7 +160,7 @@ Cypress.Commands.add('api', (options, name = 'api') => {
132160
// render the response object
133161
// TODO render headers?
134162
container.innerHTML +=
135-
'<div style="text-align: left; margin-top: 1em">\n' +
163+
'<div class="cy-api-response">\n' +
136164
`<b>Response: ${status} ${duration}ms</b>\n` +
137165
'<pre>' +
138166
JSON.stringify(body, null, 2) +

0 commit comments

Comments
 (0)