Skip to content

Performance problems with .expectJsonMatchStrict with large schema #405

@dshook

Description

@dshook

Describe the bug
When creating a matcher that has a "large" schema due to mapping over a known array to construct the schema, performance degrades quickly. In this case with 190 items in the array checking 55 fields, it takes over 9 seconds for the verification step.

await spec()
  .get(PATH)
  .withBearerToken(API_KEY_USER)
  .expectStatus(HttpResponseCode._200_Ok)
  .expectJsonMatchStrict({
    metadata: any(),
    result: arrayWith190Items.map((item) => ({
      // ... 55 fields checked with a variety of matchers
      // Some are matched against the item to make sure result returns the correct
      // data in the correct order.
    })),
    status: 'success'
  });

Changing the result matcher to use eachLike and then having an .expectJsonMatch step that matches against the array of items only takes 100ms.

To Reproduce
Steps to reproduce the behavior:

  1. Create a large schema to match against
  2. Run Test

Expected behavior
Reasonable performance with a large schema to match against

Software (please complete the following information):

  • OS: OSX
  • NodeJS Version v22.16.0
  • Test Runner vitest
  • Pactum version 3.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions