Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test(cy): simplify requesttoken handling
* Use `this.requesttoken` rather than `cy.get(@requesttoken)`
  to use the same value rather than re-evaluating the query.
* After visit `this.requesttoken` will be set.
  No need to attempt to load the token from the window
  if it is not.
* Use a simple `if` statement instead of `cypress-if`.
* This also cleans up the cypress logs significantly.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud authored and juliusknorr committed Dec 21, 2023
commit 2c8e2268dedc7ea1d28ea9c61bcd16b1028ab86e
30 changes: 9 additions & 21 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import axios from '@nextcloud/axios'
import { addCommands } from '@nextcloud/cypress'
import 'cypress-if'
import compareSnapshotCommand from 'cypress-visual-regression/dist/command.js'

// eslint-disable-next-line no-unused-vars,n/no-extraneous-import
Expand Down Expand Up @@ -57,27 +56,16 @@ Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
})

Cypress.Commands.add('getRequestToken', () => {
cy.get('@requesttoken')
.if((token) => !token)
.then(() => {
cy.window()
.then((win) => cy.wrap(win?.OC?.requestToken))
.if((token) => !!token)
.then((token) => {
cy.log('Request token from window', token)
})
cy.then(function() {
if (this.requesttoken) {
return this.requesttoken
} else {
cy.log('Fetching request token')
return cy.request('/csrftoken')
.its('body.token')
.as('requesttoken')
.else()
.then((token) => {
cy.log('Request token fetching', token)
return cy.request('/csrftoken')
.then(({ body }) => {
return body.token
})
}).as('requesttoken')
})

return cy.get('@requesttoken')
}
})
})

Cypress.Commands.add('ocsRequest', (options) => {
Expand Down
19 changes: 0 additions & 19 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
"@vue/vue2-jest": "^29.2.6",
"@vueuse/core": "^10.7.0",
"cypress": "^13.6.1",
"cypress-if": "^1.10.5",
"cypress-split": "^1.17.1",
"cypress-visual-regression": "^3.0.0",
"eslint-plugin-cypress": "^2.15.1",
Expand Down