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

Potential JSON serialization regression in 1.18.0 #270

Closed
amy-keibler opened this issue Aug 9, 2022 · 2 comments
Closed

Potential JSON serialization regression in 1.18.0 #270

amy-keibler opened this issue Aug 9, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@amy-keibler
Copy link

What happened?

Thanks for developing such a useful snapshot testing library. I'm using it in a CycloneDX SBOM library. I received a dependabot PR to bump the version to the 1.18.0 version, but that had failing tests. When I investigated, I noticed that the JSON serialization output regressed, causing tests to fail. I assume it's related to the dependency changes and is likely caused by a bug in an upstream library, but I figured I should bring it to your attention, given its impact on the snapshot output.

The short description is that it seems like pretty-printed JSON is sometimes moved to the same line as the opening {, as shown in the snapshot output for the reproduction repository

❯ less src/snapshots/example_insta_regression__tests__serializes_to_json_correctly.snap.new 
---
source: src/lib.rs
assertion_line: 22
expression: "vec![Example :: ChoiceA(ChoiceAStruct { field_a : \"a\".to_string() }), Example\n    :: ChoiceB(\"b\".to_string()),]"
---
[
  {"choiceA": {
      "fieldA": "a"
    }
  },
  {"choiceB": "b"
  }
]

Reproduction steps

I created an example repository to demonstrate the issue. There is a PR open amy-keibler/example-insta-regression#1 with failing tests that demonstrate the issue in CI

  1. Clone the linked repository
    • Observe that that the version of insta is ~1.17.1 in the main branch
  2. Run tests via cargo test and observe that they are passing
  3. Checkout the dependency-upgrade branch
    • Observe that the version of insta is 1.18.0
  4. Run tests via cargo test and observe that they are failing with the following output
    ...
    -old snapshot
    +new results
    ────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        0     0 │ [
        1       │-  {
        2       │-    "choiceA": {
              1 │+  {"choiceA": {
        3     2 │       "fieldA": "a"
        4     3 │     }
        5     4 │   },
        6       │-  {
        7       │-    "choiceB": "b"
              5 │+  {"choiceB": "b"
        8     6 │   }
        9     7 │ ]
    ────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    
    ...
    

Insta Version

1.18.0

rustc Version

No response

What did you expect?

No response

@amy-keibler amy-keibler added the bug Something isn't working label Aug 9, 2022
@mitsuhiko
Copy link
Owner

This is indeed a regression with newtype structs. Thanks for the report. I will prepare a bugfix release for this.

@mitsuhiko
Copy link
Owner

Pushed out 1.18.1 which fixes this. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants