Skip to content

Commit

Permalink
feat: move config file to home directory
Browse files Browse the repository at this point in the history
  • Loading branch information
benwainwrightcinch committed May 16, 2023
1 parent d72afca commit 2c34a9a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/components/app/app.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jest.unstable_mockModule("../trigger-form/index.js", () => ({
TriggerForm: mockTriggerForm,
}));

jest.unstable_mockModule("../../core/default-data-file-path.js", () => ({
defaultDatafile: () => `${process.cwd()}/requests.json`,
}));

let path: string | undefined;

beforeEach(async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/core/build-cli.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jest.unstable_mockModule("../components/trigger-form/index.js", () => ({
TriggerForm: mockTriggerForm,
}));

jest.unstable_mockModule("./default-data-file-path.js", () => ({
defaultDatafile: () => `${process.cwd()}/requests.json`,
}));

const { buildCli } = await import("./build-cli.js");

let path: string | undefined;
Expand Down
22 changes: 22 additions & 0 deletions src/core/default-data-file-path.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { jest } from "@jest/globals";

jest.unstable_mockModule("node:os", () => ({
homedir: jest.fn(),
}));

const os = await import("node:os");
const { defaultDatafile } = await import("./default-data-file-path.js");

beforeEach(() => {
jest.resetAllMocks();
});

describe("default data file path", () => {
it("returns the config file in the home dir", () => {
jest.mocked(os.homedir).mockReturnValue("/");

const result = defaultDatafile();

expect(result).toEqual("/.post-turtle-requests");
});
});
7 changes: 5 additions & 2 deletions src/core/default-data-file-path.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import path from "node:path";
import { join } from "node:path";
import { homedir } from "node:os";

export const defaultDatafile = () => path.join(process.cwd(), "requests.json");
const DEFAULT_FILENAME = ".post-turtle-requests";

export const defaultDatafile = () => join(homedir(), DEFAULT_FILENAME);
8 changes: 7 additions & 1 deletion src/core/load-data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mkdtemp, rmdir, writeFile } from "fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { jest } from "@jest/globals";
import { HttpRequest } from "../types/http-request.js";
import { loadData } from "./load-data.js";

let path: string | undefined;

Expand All @@ -13,6 +13,12 @@ beforeEach(async () => {
process.cwd = () => path ?? "";
});

jest.unstable_mockModule("./default-data-file-path.js", () => ({
defaultDatafile: () => `${process.cwd()}/requests.json`,
}));

const { loadData } = await import("./load-data.js");

const exampleServerHost = `http://example-server.com`;

afterEach(async () => {
Expand Down

0 comments on commit 2c34a9a

Please sign in to comment.