Skip to content

Commit

Permalink
Using generator in givePort() (#2040)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Sep 13, 2024
1 parent 218fc73 commit b05b590
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { map } from "ramda";
import { map, when, equals, nAry } from "ramda";
import { z } from "zod";
import { ezFileBrand } from "../src/file-schema";
import { SchemaHandler, walkSchema } from "../src/schema-walker";

let lastGivenPort = 8010;
const reservedPorts = {
example: 8090,
};
export const givePort = (test?: keyof typeof reservedPorts) => {
if (test && reservedPorts[test]) {
return reservedPorts[test];
}
do {
lastGivenPort++;
} while (Object.values(reservedPorts).includes(lastGivenPort));
return lastGivenPort;
};
const disposer = (function* () {
let port = 8010;
while (true) yield port++;
})();

export const givePort = (test?: "example", rsvd = 8090): number =>
test ? rsvd : when(equals(rsvd), nAry(0, givePort))(disposer.next().value);

export const serializeSchemaForTest = (
subject: z.ZodTypeAny,
Expand Down

0 comments on commit b05b590

Please sign in to comment.