Skip to content

Rails 7.1 Content-Type Issue: "An empty string is not a valid JSON string." #141

@jtannas

Description

@jtannas

Heyo - thanks for the helpful gem 🙇

We just ran into the following set of errors when upgrading from Rails 7.0 to Rails 7.1

Screenshots

image

image

Turns out JSON.parse(req.body.read) was returning an empty string because the content-type header wasn't set in the cypress request.
We managed to fix it on the client side by adding the content type header to the appCommands
image

The other way that we could get it to work was replacing JSON.parse(req.body.read) with JSON.parse(req.body) in the middleware, but decided against it because it required overriding the gem code.

https://github.com/shakacode/cypress-on-rails/blob/c36e2862a89ab117560701660f90365c08e9bfd2/lib/cypress_on_rails/middleware.rb#L54

Might be worth updating the on-rails.js template to include the content type header.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions