Skip to content

Commit 1cb6bed

Browse files
authored
feat: update example tests for compatibility with latest recommended mocha lint (#633)
* fix: ignore mocha/no-mocha-arrows linting rule * fix: merge sibling beforeeach in files example * fix: add top level context to cypress_api example * chore(deps): update eslint-plugin-mocha to 10.1.0
1 parent 666a5e7 commit 1cb6bed

File tree

5 files changed

+195
-147
lines changed

5 files changed

+195
-147
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"rules": {
1313
"indent": ["error", 2, { "SwitchCase": 1, "MemberExpression": "off" }],
14-
"mocha/no-exclusive-tests": "error"
14+
"mocha/no-exclusive-tests": "error",
15+
"mocha/no-mocha-arrows": "off"
1516
}
1617
}
Lines changed: 127 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,187 @@
11
/// <reference types="cypress" />
22

3-
context('Cypress.Commands', () => {
4-
beforeEach(() => {
5-
cy.visit('http://localhost:8080/cypress-api')
6-
})
3+
context('Cypress APIs', () => {
4+
5+
context('Cypress.Commands', () => {
6+
beforeEach(() => {
7+
cy.visit('http://localhost:8080/cypress-api')
8+
})
79

8-
// https://on.cypress.io/custom-commands
10+
// https://on.cypress.io/custom-commands
911

10-
it('.add() - create a custom command', () => {
11-
Cypress.Commands.add('console', {
12-
prevSubject: true,
13-
}, (subject, method) => {
12+
it('.add() - create a custom command', () => {
13+
Cypress.Commands.add('console', {
14+
prevSubject: true,
15+
}, (subject, method) => {
1416
// the previous subject is automatically received
1517
// and the commands arguments are shifted
1618

17-
// allow us to change the console method used
18-
method = method || 'log'
19+
// allow us to change the console method used
20+
method = method || 'log'
1921

20-
// log the subject to the console
21-
// eslint-disable-next-line no-console
22-
console[method]('The subject is', subject)
22+
// log the subject to the console
23+
// eslint-disable-next-line no-console
24+
console[method]('The subject is', subject)
2325

24-
// whatever we return becomes the new subject
25-
// we don't want to change the subject so
26-
// we return whatever was passed in
27-
return subject
28-
})
26+
// whatever we return becomes the new subject
27+
// we don't want to change the subject so
28+
// we return whatever was passed in
29+
return subject
30+
})
2931

30-
// eslint-disable-next-line no-unused-vars
31-
cy.get('button').console('info').then(($button) => {
32+
// eslint-disable-next-line no-unused-vars
33+
cy.get('button').console('info').then(($button) => {
3234
// subject is still $button
35+
})
3336
})
3437
})
35-
})
3638

37-
context('Cypress.Cookies', () => {
38-
beforeEach(() => {
39-
cy.visit('http://localhost:8080/cypress-api')
40-
})
39+
context('Cypress.Cookies', () => {
40+
beforeEach(() => {
41+
cy.visit('http://localhost:8080/cypress-api')
42+
})
4143

42-
// https://on.cypress.io/cookies
43-
it('.debug() - enable or disable debugging', () => {
44-
Cypress.Cookies.debug(true)
45-
46-
// Cypress will now log in the console when
47-
// cookies are set or cleared
48-
cy.setCookie('fakeCookie', '123ABC')
49-
cy.clearCookie('fakeCookie')
50-
cy.setCookie('fakeCookie', '123ABC')
51-
cy.clearCookie('fakeCookie')
52-
cy.setCookie('fakeCookie', '123ABC')
44+
// https://on.cypress.io/cookies
45+
it('.debug() - enable or disable debugging', () => {
46+
Cypress.Cookies.debug(true)
47+
48+
// Cypress will now log in the console when
49+
// cookies are set or cleared
50+
cy.setCookie('fakeCookie', '123ABC')
51+
cy.clearCookie('fakeCookie')
52+
cy.setCookie('fakeCookie', '123ABC')
53+
cy.clearCookie('fakeCookie')
54+
cy.setCookie('fakeCookie', '123ABC')
55+
})
5356
})
54-
})
5557

56-
context('Cypress.arch', () => {
57-
beforeEach(() => {
58-
cy.visit('http://localhost:8080/cypress-api')
59-
})
58+
context('Cypress.arch', () => {
59+
beforeEach(() => {
60+
cy.visit('http://localhost:8080/cypress-api')
61+
})
6062

61-
it('Get CPU architecture name of underlying OS', () => {
63+
it('Get CPU architecture name of underlying OS', () => {
6264
// https://on.cypress.io/arch
63-
expect(Cypress.arch).to.exist
65+
expect(Cypress.arch).to.exist
66+
})
6467
})
65-
})
6668

67-
context('Cypress.config()', () => {
68-
beforeEach(() => {
69-
cy.visit('http://localhost:8080/cypress-api')
70-
})
69+
context('Cypress.config()', () => {
70+
beforeEach(() => {
71+
cy.visit('http://localhost:8080/cypress-api')
72+
})
7173

72-
it('Get and set configuration options', () => {
74+
it('Get and set configuration options', () => {
7375
// https://on.cypress.io/config
74-
let myConfig = Cypress.config()
76+
let myConfig = Cypress.config()
7577

76-
expect(myConfig).to.have.property('animationDistanceThreshold', 5)
77-
expect(myConfig).to.have.property('baseUrl', null)
78-
expect(myConfig).to.have.property('defaultCommandTimeout', 4000)
79-
expect(myConfig).to.have.property('requestTimeout', 5000)
80-
expect(myConfig).to.have.property('responseTimeout', 30000)
81-
expect(myConfig).to.have.property('viewportHeight', 660)
82-
expect(myConfig).to.have.property('viewportWidth', 1000)
83-
expect(myConfig).to.have.property('pageLoadTimeout', 60000)
84-
expect(myConfig).to.have.property('waitForAnimations', true)
78+
expect(myConfig).to.have.property('animationDistanceThreshold', 5)
79+
expect(myConfig).to.have.property('baseUrl', null)
80+
expect(myConfig).to.have.property('defaultCommandTimeout', 4000)
81+
expect(myConfig).to.have.property('requestTimeout', 5000)
82+
expect(myConfig).to.have.property('responseTimeout', 30000)
83+
expect(myConfig).to.have.property('viewportHeight', 660)
84+
expect(myConfig).to.have.property('viewportWidth', 1000)
85+
expect(myConfig).to.have.property('pageLoadTimeout', 60000)
86+
expect(myConfig).to.have.property('waitForAnimations', true)
8587

86-
expect(Cypress.config('pageLoadTimeout')).to.eq(60000)
88+
expect(Cypress.config('pageLoadTimeout')).to.eq(60000)
8789

88-
// this will change the config for the rest of your tests!
89-
Cypress.config('pageLoadTimeout', 20000)
90+
// this will change the config for the rest of your tests!
91+
Cypress.config('pageLoadTimeout', 20000)
9092

91-
expect(Cypress.config('pageLoadTimeout')).to.eq(20000)
93+
expect(Cypress.config('pageLoadTimeout')).to.eq(20000)
9294

93-
Cypress.config('pageLoadTimeout', 60000)
95+
Cypress.config('pageLoadTimeout', 60000)
96+
})
9497
})
95-
})
9698

97-
context('Cypress.dom', () => {
98-
beforeEach(() => {
99-
cy.visit('http://localhost:8080/cypress-api')
100-
})
99+
context('Cypress.dom', () => {
100+
beforeEach(() => {
101+
cy.visit('http://localhost:8080/cypress-api')
102+
})
101103

102-
// https://on.cypress.io/dom
103-
it('.isHidden() - determine if a DOM element is hidden', () => {
104-
let hiddenP = Cypress.$('.dom-p p.hidden').get(0)
105-
let visibleP = Cypress.$('.dom-p p.visible').get(0)
104+
// https://on.cypress.io/dom
105+
it('.isHidden() - determine if a DOM element is hidden', () => {
106+
let hiddenP = Cypress.$('.dom-p p.hidden').get(0)
107+
let visibleP = Cypress.$('.dom-p p.visible').get(0)
106108

107-
// our first paragraph has css class 'hidden'
108-
expect(Cypress.dom.isHidden(hiddenP)).to.be.true
109-
expect(Cypress.dom.isHidden(visibleP)).to.be.false
109+
// our first paragraph has css class 'hidden'
110+
expect(Cypress.dom.isHidden(hiddenP)).to.be.true
111+
expect(Cypress.dom.isHidden(visibleP)).to.be.false
112+
})
110113
})
111-
})
112114

113-
context('Cypress.env()', () => {
114-
beforeEach(() => {
115-
cy.visit('http://localhost:8080/cypress-api')
116-
})
115+
context('Cypress.env()', () => {
116+
beforeEach(() => {
117+
cy.visit('http://localhost:8080/cypress-api')
118+
})
117119

118-
// We can set environment variables for highly dynamic values
120+
// We can set environment variables for highly dynamic values
119121

120-
// https://on.cypress.io/environment-variables
121-
it('Get environment variables', () => {
122+
// https://on.cypress.io/environment-variables
123+
it('Get environment variables', () => {
122124
// https://on.cypress.io/env
123125
// set multiple environment variables
124-
Cypress.env({
125-
host: 'veronica.dev.local',
126-
api_server: 'http://localhost:8888/v1/',
127-
})
126+
Cypress.env({
127+
host: 'veronica.dev.local',
128+
api_server: 'http://localhost:8888/v1/',
129+
})
128130

129-
// get environment variable
130-
expect(Cypress.env('host')).to.eq('veronica.dev.local')
131+
// get environment variable
132+
expect(Cypress.env('host')).to.eq('veronica.dev.local')
131133

132-
// set environment variable
133-
Cypress.env('api_server', 'http://localhost:8888/v2/')
134-
expect(Cypress.env('api_server')).to.eq('http://localhost:8888/v2/')
134+
// set environment variable
135+
Cypress.env('api_server', 'http://localhost:8888/v2/')
136+
expect(Cypress.env('api_server')).to.eq('http://localhost:8888/v2/')
135137

136-
// get all environment variable
137-
expect(Cypress.env()).to.have.property('host', 'veronica.dev.local')
138-
expect(Cypress.env()).to.have.property('api_server', 'http://localhost:8888/v2/')
138+
// get all environment variable
139+
expect(Cypress.env()).to.have.property('host', 'veronica.dev.local')
140+
expect(Cypress.env()).to.have.property('api_server', 'http://localhost:8888/v2/')
141+
})
139142
})
140-
})
141143

142-
context('Cypress.log', () => {
143-
beforeEach(() => {
144-
cy.visit('http://localhost:8080/cypress-api')
145-
})
144+
context('Cypress.log', () => {
145+
beforeEach(() => {
146+
cy.visit('http://localhost:8080/cypress-api')
147+
})
146148

147-
it('Control what is printed to the Command Log', () => {
149+
it('Control what is printed to the Command Log', () => {
148150
// https://on.cypress.io/cypress-log
151+
})
149152
})
150-
})
151153

152-
context('Cypress.platform', () => {
153-
beforeEach(() => {
154-
cy.visit('http://localhost:8080/cypress-api')
155-
})
154+
context('Cypress.platform', () => {
155+
beforeEach(() => {
156+
cy.visit('http://localhost:8080/cypress-api')
157+
})
156158

157-
it('Get underlying OS name', () => {
159+
it('Get underlying OS name', () => {
158160
// https://on.cypress.io/platform
159-
expect(Cypress.platform).to.be.exist
161+
expect(Cypress.platform).to.be.exist
162+
})
160163
})
161-
})
162164

163-
context('Cypress.version', () => {
164-
beforeEach(() => {
165-
cy.visit('http://localhost:8080/cypress-api')
166-
})
165+
context('Cypress.version', () => {
166+
beforeEach(() => {
167+
cy.visit('http://localhost:8080/cypress-api')
168+
})
167169

168-
it('Get current version of Cypress being run', () => {
170+
it('Get current version of Cypress being run', () => {
169171
// https://on.cypress.io/version
170-
expect(Cypress.version).to.be.exist
172+
expect(Cypress.version).to.be.exist
173+
})
171174
})
172-
})
173175

174-
context('Cypress.spec', () => {
175-
beforeEach(() => {
176-
cy.visit('http://localhost:8080/cypress-api')
177-
})
176+
context('Cypress.spec', () => {
177+
beforeEach(() => {
178+
cy.visit('http://localhost:8080/cypress-api')
179+
})
178180

179-
it('Get current spec information', () => {
181+
it('Get current spec information', () => {
180182
// https://on.cypress.io/spec
181183
// wrap the object so we can inspect it easily by clicking in the command log
182-
cy.wrap(Cypress.spec).should('include.keys', ['name', 'relative', 'absolute'])
184+
cy.wrap(Cypress.spec).should('include.keys', ['name', 'relative', 'absolute'])
185+
})
183186
})
184187
})

cypress/e2e/2-advanced-examples/files.cy.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ const requiredExample = require('../../fixtures/example')
77
context('Files', () => {
88
beforeEach(() => {
99
cy.visit('http://localhost:8080/commands/files')
10-
})
1110

12-
beforeEach(() => {
1311
// load example.json fixture file and store
1412
// in the test context object
1513
cy.fixture('example.json').as('example')

0 commit comments

Comments
 (0)