Skip to content

Add ability to save the result and other context when a check fails. #35

@steverivers

Description

@steverivers

My team currently uses k6 for performance and functional testing. One of the initial problems when we switched to k6 from our old tools was including the http request / response of failing tests into reports. We solved that by creating a fairly simple results store that we POST the test context {test_name, id, Response object etc.} to. As we prefer the chaijs fluent BDD style I created a helper that extends the assertions to send user supplied context data to our results store for reporting.

However, I'm assuming that this project is where the future of functional testing support is going to be developed. Is this something that is being considered for future work?

This is what I have come up with as a very simple proof of concept, inserting the following into expextNonRetrying.ts

  const result = checkFn();
  // If isNegated is true, we want to invert the result
  const finalResult = isNegated ? !result : result;
  if (!finalResult) {

    if (matcherSpecific?.request && matcherSpecific?.response) {
      //saveResult(matcherSpecific.request, matcherSpecific.response);
      console.log(
        "HTTP Request:",
        JSON.stringify(matcherSpecific.request, null, 2),
      );
      console.log(
        "HTTP Response:",
        JSON.stringify(matcherSpecific.response, null, 2),

      );
    } else {
      console.log("No HTTP request/response available");
    }
  }
  usedAssert(
    finalResult,
    MatcherErrorRendererRegistry.getRenderer(matcherName).render(
      info,
      MatcherErrorRendererRegistry.getConfig(),
    ),
    isSoft,
  );

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions