Skip to content

Commit 1edcb78

Browse files
committed
test(apple-runner): pick the fake runner's next reply in one helper
The request handler of the fake runner server went over the fallow complexity threshold after hangUpAlways was added. The choice of the next scripted reply is now in takeScriptedResponse. Behavior is unchanged: the apple-runner suite passes (768 tests).
1 parent f247110 commit 1edcb78

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎packages/platform-apple/src/runner/__tests__/fake-runner-server.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ export async function startFakeRunnerServer(
5757
req.on('end', () => {
5858
const body = parseBody(raw);
5959
requests.push({ command: String(body.command ?? ''), body });
60-
const queue = byCommand ? byCommand[String(body.command ?? '')] : remaining;
61-
const next =
62-
queue?.[0]?.kind === 'hangUpAlways'
63-
? queue[0]
64-
: (queue?.shift() ?? (byCommand ? { kind: 'ok' as const, data: {} } : undefined));
60+
const next = byCommand
61+
? (takeScriptedResponse(byCommand[String(body.command ?? '')]) ?? {
62+
kind: 'ok' as const,
63+
data: {},
64+
})
65+
: takeScriptedResponse(remaining);
6566
if (next?.kind === 'exit') {
6667
res.destroy();
6768
stopped ??= new Promise<void>((resolve) => server.close(() => resolve()));
@@ -84,6 +85,13 @@ export async function startFakeRunnerServer(
8485
};
8586
}
8687

88+
/** The next scripted reply; a `hangUpAlways` entry stays at the head of its queue. */
89+
function takeScriptedResponse(
90+
queue: FakeRunnerResponse[] | undefined,
91+
): FakeRunnerResponse | undefined {
92+
return queue?.[0]?.kind === 'hangUpAlways' ? queue[0] : queue?.shift();
93+
}
94+
8795
function writeFakeRunnerResponse(
8896
res: http.ServerResponse,
8997
next: Exclude<FakeRunnerResponse, { kind: 'exit' }> | undefined,

0 commit comments

Comments
 (0)