Skip to content

Commit

Permalink
fix: cy.route swallows the error about missing fixture #7818 (#7983)
Browse files Browse the repository at this point in the history
  • Loading branch information
przemuh committed Jul 27, 2020
1 parent 3ab9643 commit dbe88da
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/driver/cypress/integration/commands/fixtures_spec.js
Expand Up @@ -50,6 +50,10 @@ describe('src/cy/commands/fixtures', () => {
cy.fixture('example').should('deep.eq', { example: true })
})

it('works with null.json', () => {
cy.fixture('null.json').should('equal', null)
})

it('can read a fixture without extension with multiple dots in the name', () => {
cy.fixture('foo.bar.baz').should('deep.eq', { quux: 'quuz' })
})
Expand Down
13 changes: 13 additions & 0 deletions packages/driver/cypress/integration/commands/xhr_spec.js
Expand Up @@ -2150,6 +2150,19 @@ describe('src/cy/commands/xhr', () => {
.wrap({ foo: 'bar' }).as('foo')
.route(/foo/, '@bar')
})

// https://github.com/cypress-io/cypress/issues/7818
it('throws when fixture cannot be found', (done) => {
cy.on('fail', (err) => {
expect(err.message).to.contains('A fixture file could not be found at any of the following paths:')
done()
})

cy.route(/foo/, 'fx:NOT_EXISTING_FILE_FIXTURE')
cy.window().then((win) => {
win.$.get('/foo')
})
})
})

describe('.log', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/driver/src/cy/commands/fixtures.js
Expand Up @@ -58,10 +58,8 @@ module.exports = (Commands, Cypress, cy, state, config) => {
return Cypress.backend('get:fixture', fixture, _.pick(options, 'encoding'))
.timeout(timeout)
.then((response) => {
const err = response.__error

if (err) {
return $errUtils.throwErr(err)
if (response && response.__error) {
return $errUtils.throwErr(response.__error)
}

// add the fixture to the cache
Expand Down
11 changes: 10 additions & 1 deletion packages/driver/src/cy/commands/xhr.js
Expand Up @@ -200,7 +200,7 @@ const startXhrServer = (cy, state, config) => {
},

onFixtureError (xhr, err) {
err = $errUtils.cypressErr(err)
err = $errUtils.cypressErr({ message: err })

return this.onError(xhr, err)
},
Expand Down Expand Up @@ -471,6 +471,15 @@ module.exports = (Commands, Cypress, cy, state, config) => {
})
}

// look ahead to see if fixture exists
const fixturesRe = /^(fx:|fixture:)/

if (hasResponse && fixturesRe.test(options.response)) {
const fixtureName = options.response.replace(fixturesRe, '')

return cy.now('fixture', fixtureName).then(() => route())
}

return route()
}

Expand Down

3 comments on commit dbe88da

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dbe88da Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/linux-x64/circle-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-407448/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/circle-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-407438/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dbe88da Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dbe88da Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-dbe88dad15325b08acdbe601a7af494b3fd998b0-34329162/cypress.tgz

Please sign in to comment.