Skip to content

Commit

Permalink
Moved code to minimize code diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Crustum7 committed Oct 9, 2023
1 parent 4b6796c commit dae4e2b
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions packages/driver/src/cy/commands/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,37 @@ interface BackendError {
}

export default (Commands, Cypress, cy, state, config) => {
Commands.addAll({
// allow our signature to be similar to cy.intercept
// METHOD / URL / BODY
// or object literal with all expanded options
request (...args) {
let fxArg = ''

if (args.length === 2) {
fxArg = args[1]
// Default to POST
if (hasFixturePrefix(fxArg)) {
args = ['POST', ...args]
}
} else if (args.length === 3) {
fxArg = args[2]
}

if (hasFixturePrefix(fxArg)) {
const fxName = fxArg.split(':')[1]

return cy.fixture(fxName).then((fixtureData) => {
args[2] = fixtureData

return requestHandler(...args)
})
}

return requestHandler(...args)
},
})

const requestHandler = function (...args) {
const o: any = {}
const userOptions = o
Expand Down Expand Up @@ -423,35 +454,4 @@ export default (Commands, Cypress, cy, state, config) => {
})
})
}

Commands.addAll({
// allow our signature to be similar to cy.intercept
// METHOD / URL / BODY
// or object literal with all expanded options
request (...args) {
let fxArg = ''

if (args.length === 2) {
fxArg = args[1]
// Default to POST
if (hasFixturePrefix(fxArg)) {
args = ['POST', ...args]
}
} else if (args.length === 3) {
fxArg = args[2]
}

if (hasFixturePrefix(fxArg)) {
const fxName = fxArg.split(':')[1]

return cy.fixture(fxName).then((fixtureData) => {
args[2] = fixtureData

return requestHandler(...args)
})
}

return requestHandler(...args)
},
})
}

0 comments on commit dae4e2b

Please sign in to comment.