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

stubbing a XHR call using a fixture file with null content raises an error #472

Closed
andreaazzara opened this issue Mar 22, 2017 · 3 comments · Fixed by #5562 · May be fixed by ngChile/ngx-devkit-cypress-builder#20 or qsays/grafana#1
Closed

Comments

@andreaazzara
Copy link

@andreaazzara andreaazzara commented Mar 22, 2017

Current behavior:

when stubbing a XHR call using a fixture file with null content an error is raised

Expected behavior:

JSON.parse('null') returns null, no error is raised

How to reproduce the current behavior:

cy.server().route({
  method: 'GET',
  url: 'some/url',
  response: 'fixture:stub_file.json'
})

where stub_file.json is a file containing the string
null

Additional Info (images, notes, stack traces, etc)

Error trace

Error:        CypressError: TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
    at fromObject (buffer.js:259:9)
    at Function.Buffer.from (buffer.js:96:10)
    at new Buffer (buffer.js:75:17)
    at Object.<anonymous> (/Applications/Cypress.app/Contents/Resources/app/index.js:1804:21)
    at Object.tryCatcher (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:636:18)
    at Promise._resolveCallback (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:431:57)
    at Promise._settlePromiseFromHandler (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:522:17)
    at Promise._settlePromise (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:636:18)
    at Promise._settlePromise (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:580:21)
    at Promise._settlePromise0 (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:636:18)
    at Promise._resolveCallback (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:431:57)
    at Promise._settlePromiseFromHandler (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:522:17)
    at Promise._settlePromise (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:636:18)
    at Promise._settlePromise (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:580:21)
    at Promise._settlePromise0 (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:636:18)
    at Promise._resolveCallback (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:431:57)
    at Promise._settlePromiseFromHandler (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:522:17)
    at Promise._settlePromise (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:636:18)
    at Promise._resolveCallback (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:431:57)
    at Promise._settlePromiseFromHandler (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:522:17)
    at Promise._settlePromise (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/promise.js:636:18)
    at /Applications/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/nodeback.js:42:21
    at /Applications/Cypress.app/Contents/Resources/app/node_modules/graceful-fs/graceful-fs.js:78:16
    at tryToString (fs.js:455:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
  • Operating System: OSX Sierra
  • Cypress Version: 0.19.1
@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Mar 23, 2017

Can verify this bug. This actually occurs on the XHR Stub of the route, not on the invocation of the cy.route() with null fixture data itself.

This is fine:

cy
  .server()
  .route({
    method: "GET",
    url: /comments/,
    response: 'fixture:null-data.json'
  })

This is not fine:

cy
  .server()
  .route({
    method: "GET",
    url: /comments/,
    response: 'fixture:null-data.json'
  })

  // clicking this button initiates out GET to /comments/
  .get('.fixture-btn').click()

screen shot 2017-03-23 at 1 05 38 pm

@jennifer-shehane jennifer-shehane added difficulty: 1️⃣ stage: ready for work labels Feb 1, 2019
@cypress-bot cypress-bot bot added stage: work in progress and removed stage: ready for work labels Nov 1, 2019
@cypress-bot cypress-bot bot added stage: needs review stage: work in progress and removed stage: work in progress stage: needs review labels Nov 26, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: work in progress labels Nov 27, 2019
@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Nov 27, 2019

The code for this is done in cypress-io/cypress#5562, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Nov 27, 2019

Released in 3.7.0.

@cypress-bot cypress-bot bot removed the stage: pending release label Nov 27, 2019
@cypress-io cypress-io locked as resolved and limited conversation to collaborators Dec 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.