Skip to content

Commit 533e34c

Browse files
authored
fix: make work with Cypress v12 (#185)
* refactor specs a little * fix: work with Cypress v12
1 parent 5a27aa7 commit 533e34c

7 files changed

+474
-349
lines changed

.prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 2,
4+
"semi": false,
5+
"singleQuote": true
6+
}

cypress/e2e/hides-credentials.cy.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// loads definition for the custom "cy.api" command
2+
/// <reference path="../../dist/types.d.ts" />
3+
4+
describe('cy.api', () => {
5+
it('mask credentials bearer and password', () => {
6+
cy.api({
7+
url: '/',
8+
auth: {
9+
bearer: 'bearer',
10+
username: 'login',
11+
password: 'password',
12+
},
13+
}).then((response) => {
14+
expect(response.status).eq(200)
15+
cy.contains('"bearer": "*****"')
16+
cy.contains('"password": "*****"')
17+
})
18+
})
19+
})

cypress/e2e/shows-credentials.cy.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// loads definition for the custom "cy.api" command
2+
/// <reference path="../../dist/types.d.ts" />
3+
4+
describe('cy.api', () => {
5+
it(
6+
'show credentials',
7+
{
8+
env: {
9+
API_SHOW_CREDENTIALS: true,
10+
},
11+
},
12+
() => {
13+
cy.api({
14+
url: '/',
15+
auth: {
16+
bearer: 'bearer',
17+
username: 'login',
18+
password: 'password',
19+
},
20+
}).then((response) => {
21+
expect(response.status).eq(200)
22+
cy.contains('"bearer": "bearer"')
23+
cy.contains('"password": "password"')
24+
})
25+
},
26+
)
27+
})

cypress/e2e/spec.cy.ts

+89-125
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@
33

44
describe('cy.api', () => {
55
it('calls API method', () => {
6-
cy.api(
7-
{
8-
url: '/'
9-
}
10-
)
6+
cy.api({
7+
url: '/',
8+
})
119
})
1210

13-
it('calls API without displaying request', { apiDisplayRequest: false }, () => {
14-
cy.get('body').should('not.contain', 'MY PAGE')
15-
cy.api(
16-
{
17-
url: '/',
18-
}
19-
)
20-
cy.get('.container').should('not.contain', 'Request')
21-
cy.visit('/test.html')
22-
cy.contains('MY PAGE')
23-
cy.url().should('contain', 'test.html')
24-
cy.api(
25-
{
11+
it(
12+
'calls API without displaying request',
13+
{ apiDisplayRequest: false },
14+
() => {
15+
cy.get('body').should('not.contain', 'MY PAGE')
16+
cy.api({
2617
url: '/',
27-
},
28-
'hello world'
29-
)
30-
cy.contains('MY PAGE')
31-
cy.get('.container').should('not.contain', 'Request')
32-
})
18+
})
19+
cy.get('.container').should('not.contain', 'Request')
20+
cy.visit('/test.html')
21+
cy.contains('MY PAGE')
22+
cy.url().should('contain', 'test.html')
23+
cy.api(
24+
{
25+
url: '/',
26+
},
27+
'hello world',
28+
)
29+
cy.contains('MY PAGE')
30+
cy.get('.container').should('not.contain', 'Request')
31+
},
32+
)
3333

3434
it('calls several times', () => {
3535
const options = { url: '/' }
@@ -41,17 +41,17 @@ describe('cy.api', () => {
4141
it('yields API call result', () => {
4242
cy.api(
4343
{
44-
url: '/'
44+
url: '/',
4545
},
46-
'my hello world'
47-
).then(response => {
46+
'my hello world',
47+
).then((response) => {
4848
expect(response).to.include.keys([
4949
'status',
5050
'statusText',
5151
'body',
5252
'requestHeaders',
5353
'headers',
54-
'duration'
54+
'duration',
5555
])
5656
expect(response.body).to.equal('Hello World!')
5757
})
@@ -60,132 +60,96 @@ describe('cy.api', () => {
6060
it('yields result that has log messages', () => {
6161
cy.api(
6262
{
63-
url: '/'
63+
url: '/',
6464
},
65-
'hello world'
65+
'hello world',
6666
).then(({ messages }) => {
6767
console.table(messages)
6868
// filter for "console.log" messages
6969
const logs = Cypress._.filter(messages, {
7070
type: 'console',
71-
namespace: 'log'
71+
namespace: 'log',
7272
})
7373
expect(logs, '1 console.log message').to.have.length(1)
7474
expect(logs[0]).to.deep.include({
7575
type: 'console',
7676
namespace: 'log',
77-
message: 'processing GET /'
77+
message: 'processing GET /',
7878
})
7979
})
8080
})
8181

82-
83-
it('yields result that has log messages with API_MESSAGES true', {
84-
env: {
85-
API_MESSAGES: true
86-
}
87-
}, () => {
88-
cy.api(
89-
{
90-
url: '/'
82+
it(
83+
'yields result that has log messages with API_MESSAGES true',
84+
{
85+
env: {
86+
API_MESSAGES: true,
9187
},
92-
'hello world'
93-
).then(({ messages }) => {
94-
console.table(messages)
95-
// filter for "console.log" messages
96-
const logs = Cypress._.filter(messages, {
97-
type: 'console',
98-
namespace: 'log'
88+
},
89+
() => {
90+
cy.api(
91+
{
92+
url: '/',
93+
},
94+
'hello world',
95+
).then(({ messages }) => {
96+
console.table(messages)
97+
// filter for "console.log" messages
98+
const logs = Cypress._.filter(messages, {
99+
type: 'console',
100+
namespace: 'log',
101+
})
102+
expect(logs, '1 console.log message').to.have.length(1)
103+
expect(logs[0]).to.deep.include({
104+
type: 'console',
105+
namespace: 'log',
106+
message: 'processing GET /',
107+
})
99108
})
100-
expect(logs, '1 console.log message').to.have.length(1)
101-
expect(logs[0]).to.deep.include({
102-
type: 'console',
103-
namespace: 'log',
104-
message: 'processing GET /'
105-
})
106-
})
107-
})
109+
},
110+
)
108111

109-
it('no log messages with API_MESSAGES false', {
110-
env: {
111-
API_MESSAGES: false
112-
}
113-
}, () => {
114-
cy.api(
115-
{
116-
url: '/'
112+
it(
113+
'no log messages with API_MESSAGES false',
114+
{
115+
env: {
116+
API_MESSAGES: false,
117117
},
118-
'hello world'
119-
).then(({ messages }) => {
120-
expect(messages).to.have.length(0)
121-
})
122-
})
118+
},
119+
() => {
120+
cy.api(
121+
{
122+
url: '/',
123+
},
124+
'hello world',
125+
).then(({ messages }) => {
126+
expect(messages).to.have.length(0)
127+
})
128+
},
129+
)
123130

124131
it('mask credentials bearer', () => {
125-
cy.api(
126-
{
127-
url: '/',
128-
auth: {
129-
bearer: 'bearer'
130-
}
131-
}
132-
).then(response => {
132+
cy.api({
133+
url: '/',
134+
auth: {
135+
bearer: 'bearer',
136+
},
137+
}).then((response) => {
133138
expect(response.status).eq(200)
134139
cy.contains('"bearer": "*****"')
135140
})
136141
})
137142

138143
it('mask credentials password', () => {
139-
cy.api(
140-
{
141-
url: '/',
142-
auth: {
143-
username: 'login',
144-
password: 'password'
145-
}
146-
}
147-
).then(response => {
148-
expect(response.status).eq(200)
149-
cy.contains('"password": "*****"')
150-
})
151-
})
152-
153-
it('mask credentials bearer and password', () => {
154-
cy.api(
155-
{
156-
url: '/',
157-
auth: {
158-
bearer: 'bearer',
159-
username: 'login',
160-
password: 'password'
161-
}
162-
}
163-
).then(response => {
144+
cy.api({
145+
url: '/',
146+
auth: {
147+
username: 'login',
148+
password: 'password',
149+
},
150+
}).then((response) => {
164151
expect(response.status).eq(200)
165-
cy.contains('"bearer": "*****"')
166152
cy.contains('"password": "*****"')
167153
})
168154
})
169-
170-
it('show credentials', {
171-
env: {
172-
API_SHOW_CREDENTIALS: true
173-
}
174-
}, () => {
175-
cy.api(
176-
{
177-
url: '/',
178-
auth: {
179-
bearer: 'bearer',
180-
username: 'login',
181-
password: 'password'
182-
}
183-
}
184-
).then(response => {
185-
expect(response.status).eq(200)
186-
cy.contains('"bearer": "bearer"')
187-
cy.contains('"password": "password"')
188-
})
189-
})
190-
191155
})

0 commit comments

Comments
 (0)