playwright-test-commons - v0.8.0
    Preparing search index...

    Function timingCheck

    • Measures calls with Playwright's resource timing (response.timing()) and asserts (soft) that their average is within a limit. Each call is timed from the request being sent to the last byte arriving, so DNS lookup, connection and TLS setup never count against the API. Logs each duration and the average time to first byte.

      Parameters

      • apiCall: () => Promise<APIResponse<unknown>>

        makes the request, e.g. () => Products.list()

      • maxAverageMs: number = 1000

        the highest acceptable average. Default 1000

      • options: TimingOptions = {}

      Returns Promise<TimingResult>

      the measurements, for further assertions

      await timingCheck(() => Products.list(), 800);
      const { timeToFirstByte } = await timingCheck(() => Products.search("top"), 1000, { runs: 10 });