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

Upgrade Vitest to 1.6.0 To Reduce Serialized Error Payload Length #2246

Closed
Torres-ssf opened this issue May 6, 2024 · 0 comments · Fixed by #2247
Closed

Upgrade Vitest to 1.6.0 To Reduce Serialized Error Payload Length #2246

Torres-ssf opened this issue May 6, 2024 · 0 comments · Fixed by #2247
Assignees
Labels
chore Issue is a chore

Comments

@Torres-ssf
Copy link
Contributor

When Vitest encounters a class instance within an Error object during serialization, it attempts to serialize the instance's properties and methods. For example, if it finds a BN instance, instead of merely serializing straightforward properties like:

{ 
  negative: +0, 
  words: [ 33554432, 55592226, 34 ], 
  length: 3, 
  red: null, 
  MAX_U64: '0xFFFFFFFFFFFFFFFF' 
},

It would serialize the entire structure, including methods and potentially inherited properties, resulting in a detailed and extensive output like:

{
  // ... properties from the above example,
  "constructor": "Function<BN>",
  "toString": "Function<toString>",
  "toHex": "Function<toHex>",
  "neg": "Function<neg>",
  "abs": "Function<abs>",
  ...
}

This issue arises because Vitest does not automatically invoke the toJSON method on custom Error implementations, instead opting to manually serialize every attribute it encounters within the instances/objects.

However, this is fixed on 1.6.0

Before 1.6.0 ( not even half of the full error ):
Screenshot 2024-05-06 at 13 09 54

After 1.6.0 ( whole error ):
Screenshot 2024-05-06 at 13 10 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Issue is a chore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant