Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cy.route swallows the error about missing fixture #7818 #7983

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions packages/driver/cypress/integration/commands/fixtures_spec.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const startXhrServer = (cy, state, config) => {
},

onFixtureError (xhr, err) {
err = $errUtils.cypressErr(err)
err = $errUtils.cypressErr({ message: err })
bahmutov marked this conversation as resolved.
Show resolved Hide resolved

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:)/
bahmutov marked this conversation as resolved.
Show resolved Hide resolved

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

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

return route()
}

Expand Down