Skip to content

Commit

Permalink
Merge e2bb5dc into 6cde2f4
Browse files Browse the repository at this point in the history
  • Loading branch information
teklakct committed Jul 12, 2022
2 parents 6cde2f4 + e2bb5dc commit 22adb42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Config } from "./types";
import { getDynalitePort, setConfigDir } from "./config";

const BASE_PORT = 8443;
const DEFAULT_BASE_PORT = 8000;

const mockedConfig = jest.fn((): Config => ({ basePort: BASE_PORT }));
const configPath = "/fakepath/jest-dynalite-config.js";
Expand Down Expand Up @@ -40,18 +39,21 @@ describe("Config", () => {
const port = getDynalitePort();

expect(port).not.toBeNaN();
expect(port).toBe(BASE_PORT);
expect(port).toBe(BASE_PORT + 1);

process.env.JEST_WORKER_ID = workerId;
});

test("if basePort is not defined then port 8000 will be used as a default", () => {
test("if basePort is not defined then port 8001 will be used as a default", () => {
const workerId = process.env.JEST_WORKER_ID;
delete process.env.JEST_WORKER_ID;

jest.resetModules();
mockedConfig.mockReturnValue({});
const expectedPort =
DEFAULT_BASE_PORT + parseInt(process.env.JEST_WORKER_ID || "0", 10);

expect(getDynalitePort()).toBe(expectedPort);
expect(getDynalitePort()).toBe(8001);

process.env.JEST_WORKER_ID = workerId;
});

test("should throw an error if basePort in config file is invalid", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const setConfigDir = (directory: string): void => {
export const getDynalitePort = (): number => {
const { basePort = 8000 } = readConfig();
if (Number.isInteger(basePort) && basePort > 0 && basePort <= 65535) {
return basePort + parseInt(process.env.JEST_WORKER_ID || "0", 10);
return basePort + parseInt(process.env.JEST_WORKER_ID || "1", 10);
}

throw new TypeError(
Expand Down

0 comments on commit 22adb42

Please sign in to comment.