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

bun test toMatchInlineSnapshot fails due to backtick string indentation #16403

Open
wavedeck opened this issue Jan 14, 2025 · 0 comments · May be fixed by #16685
Open

bun test toMatchInlineSnapshot fails due to backtick string indentation #16403

wavedeck opened this issue Jan 14, 2025 · 0 comments · May be fixed by #16685
Assignees
Labels
bug Something isn't working bun:test Something related to the `bun test` runner confirmed bug We can reproduce this issue

Comments

@wavedeck
Copy link

wavedeck commented Jan 14, 2025

What version of Bun is running?

1.1.44-canary.57+cc8ec65e3

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

I wanted to test the compatibility of @apollo/server with bun and wanted to try out bun's own jest compatible test runner bun test

when i ran the tests, i've noticed tests failing that are using .toMatchInlineSnapshot matchers (which bun lists as implemented), that otherwise succeed in node.js with jest.

Upon closer inspection, i've noticed that the "Expected" part of the failing tests are indented just like the given string in the test file, while the "Received" part shows the value as received with a different indentation. This indentation mismatch causes the test to fail, although it doesn't do that in jest.

for an example see the errors.test.ts in the apollo-server repository.

https://github.com/apollographql/apollo-server/blob/a94828d0bca58ba862e9d02b06d076d478b98446/packages/server/src/__tests__/errors.test.ts#L120

To confirm this behavior, i've modified this file locally to put the backtick string at the very start of the line and further modified the indentation (2 spaces instead of 4 originally) to match the result output of bun test. The test then passes.

What is the expected behavior?

.toMatchInlineSnapshot should ignore indentation just like in jest. At very least when the string passed is a serialized JSON object like in the example.

https://github.com/apollographql/apollo-server/blob/a94828d0bca58ba862e9d02b06d076d478b98446/packages/server/src/__tests__/errors.test.ts#L120

What do you see instead?

No response

Additional information

Expected: 
          {
            "extensions": {
              "code": "INTERNAL_SERVER_ERROR",
              "exception": {
                "key": "value",
              },
            },
            "message": "message",
          }
        
Received: 
{
  "extensions": {
    "code": "INTERNAL_SERVER_ERROR",
    "exception": {
      "key": "value",
    },
  },
  "message": "message",
}


      at <anonymous> (/Users/david-ix/Desktop/apollo-server/packages/server/src/__tests__/errors.test.ts:119:23)
@wavedeck wavedeck added bug Something isn't working needs triage labels Jan 14, 2025
@RiskyMH RiskyMH added bun:test Something related to the `bun test` runner and removed needs triage labels Jan 15, 2025
@pfgithub pfgithub added the confirmed bug We can reproduce this issue label Jan 23, 2025
@pfgithub pfgithub self-assigned this Jan 23, 2025
@pfgithub pfgithub linked a pull request Jan 24, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun:test Something related to the `bun test` runner confirmed bug We can reproduce this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants