From dae4e2b76f9ceae24d86601941891a65f50848cf Mon Sep 17 00:00:00 2001 From: Martin Jonson Date: Mon, 9 Oct 2023 14:44:20 +0200 Subject: [PATCH] Moved code to minimize code diff --- packages/driver/src/cy/commands/request.ts | 62 +++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/driver/src/cy/commands/request.ts b/packages/driver/src/cy/commands/request.ts index 9f2dc4ba5b3f..9f6430512c8b 100644 --- a/packages/driver/src/cy/commands/request.ts +++ b/packages/driver/src/cy/commands/request.ts @@ -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 @@ -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) - }, - }) }