Skip to content

Commit d39c9b3

Browse files
authored
Merge pull request #4364 from nextcloud/ci/flaky-cypress
2 parents d540b47 + 33372da commit d39c9b3

7 files changed

Lines changed: 62 additions & 68 deletions

File tree

cypress/e2e/attachments.spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222

2323
import { initUserAndFiles, randHash, randUser } from '../utils/index.js'
24-
import 'cypress-file-upload'
2524

2625
const user = randUser()
2726
const recipient = randUser()
@@ -41,7 +40,12 @@ function attachFile(name, requestAlias = null) {
4140
}
4241
return cy.getEditor()
4342
.find('input[type="file"][data-text-el="attachment-file-input"]')
44-
.attachFile(name)
43+
.selectFile([
44+
{
45+
contents: 'cypress/fixtures/' + name,
46+
fileName: name,
47+
},
48+
], { force: true })
4549
}
4650

4751
/**
@@ -406,10 +410,4 @@ describe('Test all attachment insertion methods', () => {
406410
}
407411
})
408412
})
409-
410-
it('Delete the user', () => {
411-
cy.deleteUser(user)
412-
cy.deleteUser(recipient)
413-
})
414-
415413
})

cypress/e2e/nodes/ImageView.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ describe('Image View', () => {
1515
before(() => {
1616
cy.createUser(user)
1717
cy.login(user)
18-
cy.visit('/apps/files')
1918

2019
// Upload test files to user's storage
2120
cy.createFolder('child-folder')

cypress/e2e/nodes/Mentions.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { initUserAndFiles, randUser } from '../../utils/index.js'
2-
import 'cypress-file-upload'
32

43
const user = randUser()
54
const mentionMe = randUser()

cypress/e2e/sync.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ describe('Sync', () => {
6666

6767
it('recovers from a lost connection', () => {
6868
let count = 0
69+
cy.intercept({ method: 'PUT', url: '**/apps/text/session/create' })
70+
.as('createSession')
6971
cy.intercept({ method: 'POST', url: '**/apps/text/session/*' }, (req) => {
7072
if (count < 4) {
7173
req.destroy()
@@ -86,6 +88,9 @@ describe('Sync', () => {
8688
cy.wait('@syncAfterRecovery', { timeout: 30000 })
8789
cy.get('#editor-container .document-status', { timeout: 30000 })
8890
.should('not.contain', 'File could not be loaded')
91+
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
92+
cy.wait('@createSession')
93+
cy.wait('@syncAfterRecovery')
8994
cy.getContent().type('* more content added after the lost connection{enter}')
9095
cy.wait('@syncAfterRecovery')
9196
cy.closeFile()

cypress/support/commands.js

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,61 @@ addCommands()
3636
// and also to determine paths, urls and the like.
3737
let auth
3838
Cypress.Commands.overwrite('login', (login, user) => {
39+
cy.window().then((win) => {
40+
win.location.href = 'about:blank'
41+
})
3942
auth = { user: user.userId, password: user.password }
4043
login(user)
4144
})
4245

4346
Cypress.Commands.add('ocsRequest', (options) => {
44-
return cy.request({
45-
form: true,
46-
auth,
47-
headers: {
48-
'OCS-ApiRequest': 'true',
49-
'Content-Type': 'application/x-www-form-urlencoded',
50-
},
51-
...options,
52-
})
47+
return cy.request('/csrftoken')
48+
.then(({ body }) => body.token)
49+
.then(requesttoken => {
50+
return cy.request({
51+
form: true,
52+
auth,
53+
headers: {
54+
'OCS-ApiRequest': 'true',
55+
'Content-Type': 'application/x-www-form-urlencoded',
56+
requesttoken,
57+
},
58+
...options,
59+
})
60+
})
5361
})
5462

5563
Cypress.Commands.add('uploadFile', (fileName, mimeType, target) => {
56-
return cy.fixture(fileName, 'base64')
57-
.then(Cypress.Blob.base64StringToBlob)
64+
return cy.fixture(fileName, 'binary')
65+
.then(Cypress.Blob.binaryStringToBlob)
5866
.then(blob => {
59-
const file = new File([blob], fileName, { type: mimeType })
6067
if (typeof target !== 'undefined') {
6168
fileName = target
6269
}
63-
return cy.request('/csrftoken')
64-
.then(({ body }) => body.token)
65-
.then(requesttoken => {
66-
return axios.put(`${url}/remote.php/webdav/${fileName}`, file, {
70+
cy.request('/csrftoken')
71+
.then(({ body }) => {
72+
return cy.wrap(body.token)
73+
})
74+
.then(async (requesttoken) => {
75+
return cy.request({
76+
url: `${url}/remote.php/webdav/${fileName}`,
77+
method: 'put',
78+
body: blob.size > 0 ? blob : '',
79+
auth,
6780
headers: {
6881
requesttoken,
6982
'Content-Type': mimeType,
7083
},
71-
}).then(response => {
72-
const fileId = Number(
73-
response.headers['oc-fileid']?.split('oc')?.[0]
74-
)
75-
cy.log(`Uploaded ${fileName}`,
76-
response.status,
77-
{ fileId }
78-
)
79-
return fileId
8084
})
85+
}).then(response => {
86+
const fileId = Number(
87+
response.headers['oc-fileid']?.split('oc')?.[0]
88+
)
89+
cy.log(`Uploaded ${fileName}`,
90+
response.status,
91+
{ fileId }
92+
)
93+
return cy.wrap(fileId)
8194
})
8295
})
8396
})
@@ -95,27 +108,27 @@ Cypress.Commands.add('downloadFile', (fileName) => {
95108
})
96109

97110
Cypress.Commands.add('createFile', (target, content, mimeType = 'text/markdown') => {
98-
const fileName = target.split('/').pop()
99-
100111
const blob = new Blob([content], { type: mimeType })
101-
const file = new File([blob], fileName, { type: mimeType })
102112

103-
return cy.window()
104-
.then(async win => {
105-
const response = await axios.put(`${url}/remote.php/webdav/${target}`, file, {
113+
return cy.request('/csrftoken')
114+
.then(({ body }) => body.token)
115+
.then(requesttoken => {
116+
return cy.request({
117+
url: `${url}/remote.php/webdav/${target}`,
118+
method: 'put',
119+
body: blob.size > 0 ? blob : '',
120+
auth,
106121
headers: {
107-
requesttoken: win.OC.requestToken,
108122
'Content-Type': mimeType,
123+
requesttoken,
109124
},
125+
}).then((response) => {
126+
return cy.log(`Uploaded ${target}`, response.status)
110127
})
111-
112-
return cy.log(`Uploaded ${fileName}`, response.status)
113128
})
114-
115129
})
116130

117131
Cypress.Commands.add('shareFileToUser', (path, targetUser, shareData = {}) => {
118-
cy.clearCookies()
119132
cy.ocsRequest({
120133
method: 'POST',
121134
url: `${url}/ocs/v2.php/apps/files_sharing/api/v1/shares`,
@@ -212,7 +225,8 @@ Cypress.Commands.add('createFolder', (target) => {
212225
return cy.request('/csrftoken')
213226
.then(({ body }) => body.token)
214227
.then(requesttoken => {
215-
return axios.request(`${rootPath}/${dirPath}`, {
228+
return cy.request({
229+
url: `${rootPath}/${dirPath}`,
216230
method: 'MKCOL',
217231
auth,
218232
headers: {

package-lock.json

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
"@vue/test-utils": "^1.3.0 <2",
125125
"@vue/vue2-jest": "^29.2.4",
126126
"cypress": "^12.15.0",
127-
"cypress-file-upload": "^5.0.8",
128127
"eslint-plugin-cypress": "^2.13.3",
129128
"identity-obj-proxy": "^3.0.0",
130129
"jest": "^29.5.0",

0 commit comments

Comments
 (0)