Skip to content

Commit

Permalink
fix: mock os platform func
Browse files Browse the repository at this point in the history
  • Loading branch information
joset98 committed Jan 27, 2025
1 parent d99b951 commit 57d1ba3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions utils/convertPathToUnixStyle.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import os from "os";
import { jest } from "@jest/globals";
import { convertPathToUnixStyle } from "./convertPathToUnixStyle.js";

describe("Convert path to unix style tests", () => {
const osMock = jest.spyOn(os, "platform");
let originalPlatform;

beforeEach(() => {
jest.clearAllMocks();
jest.resetModules();
});

beforeAll(() => {
originalPlatform = process.platform;
});
Expand All @@ -19,6 +27,7 @@ describe("Convert path to unix style tests", () => {
Object.defineProperty(process, "platform", {
value: "linux",
});
osMock.mockImplementation(() => "linux");

const filePath = "/home/user/Documents/file.txt";
expect(convertPathToUnixStyle(filePath)).toBe(filePath);
Expand All @@ -29,6 +38,7 @@ describe("Convert path to unix style tests", () => {
Object.defineProperty(process, "platform", {
value: "win32",
});
osMock.mockImplementation(() => "win32");

const windowsPath = "C:\\Users\\user\\Documents\\file.txt";
const expectedUnixPath = "C:/Users/user/Documents/file.txt";
Expand All @@ -38,7 +48,10 @@ describe("Convert path to unix style tests", () => {
it("Should handle paths with multiple backslashes on Windows", () => {
Object.defineProperty(process, "platform", {
value: "win32",
writable: true,
});
osMock.mockImplementation(() => "win32");

const windowsPath = "C:\\\\Users\\\\user\\\\Documents\\\\file.txt";
const expectedUnixPath = "C:/Users/user/Documents/file.txt";
expect(convertPathToUnixStyle(windowsPath)).toBe(expectedUnixPath);
Expand Down

0 comments on commit 57d1ba3

Please sign in to comment.