Skip to content

Commit

Permalink
fix: Request recording abandons test recording
Browse files Browse the repository at this point in the history
  • Loading branch information
zermelo-wisen committed Apr 2, 2024
1 parent b449c14 commit 828f054
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/hooks/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check failure on line 13 in src/hooks/http.ts

View workflow job for this annotation

GitHub Actions / lint

'record' is defined but never used
import { getTime } from "../util/getTime";

type HTTP = typeof http | typeof https;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/jest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from "node:assert";
import { pathToFileURL } from "node:url";

import type { Circus } from "@jest/types";
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 828f054

Please sign in to comment.