From 828f05410398638c4b0e3db50f80cbe9e422868d Mon Sep 17 00:00:00 2001 From: zermelo-wisen Date: Tue, 2 Apr 2024 12:57:37 +0300 Subject: [PATCH] fix: Request recording abandons test recording --- src/hooks/http.ts | 8 +++++--- src/hooks/jest.ts | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/hooks/http.ts b/src/hooks/http.ts index fac529ae..6ca43c79 100644 --- a/src/hooks/http.ts +++ b/src/hooks/http.ts @@ -10,7 +10,7 @@ import config from "../config"; import Recording from "../Recording"; import { info, warn } from "../message"; import { parameter } from "../parameter"; -import { recording, start } from "../recorder"; +import { record, recording, start } from "../recorder"; import { getTime } from "../util/getTime"; type HTTP = typeof http | typeof https; @@ -256,7 +256,8 @@ function handleRequest(request: http.IncomingMessage, response: http.ServerRespo if (shouldIgnoreRequest(request)) return; const url = new URL(request.url, "http://example"); - const timestamp = remoteRunning ? undefined : startRequestRecording(url.pathname); + const testRunning = recording.metadata.recorder.type == "tests"; + const timestamp = remoteRunning || testRunning ? undefined : startRequestRecording(url.pathname); const requestEvent = recording.httpRequest( request.method, url.pathname, @@ -351,7 +352,8 @@ function handleResponse( normalizeHeaders(response.getHeaders()), capture.createReturnValue(isJson), ); - if (remoteRunning) return; + if (remoteRunning || recording.metadata.recorder.type == "tests") return; + const { request_method, path_info } = requestEvent.http_server_request; recording.metadata.name = `${request_method} ${path_info} (${response.statusCode}) — ${timestamp}`; recording.finish(); diff --git a/src/hooks/jest.ts b/src/hooks/jest.ts index 622193b5..60a19cc6 100644 --- a/src/hooks/jest.ts +++ b/src/hooks/jest.ts @@ -1,3 +1,4 @@ +import assert from "node:assert"; import { pathToFileURL } from "node:url"; import type { Circus } from "@jest/types"; @@ -58,10 +59,12 @@ function eventHandler(event: Circus.Event) { start(createRecording(event.test)); break; case "test_fn_failure": + assert(recording.metadata.recorder.type == "tests"); recording.metadata.test_status = "failed"; recording.metadata.exception = exceptionMetadata(event.error); return recording.finish(); case "test_fn_success": + assert(recording.metadata.recorder.type == "tests"); recording.metadata.test_status = "succeeded"; return recording.finish(); }