Skip to content

Commit

Permalink
fix: fixed wrong test for get-npmrc-path
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed May 23, 2024
1 parent d09f625 commit 8f86d0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type AggregateError from "aggregate-error";
import { beforeEach, describe, expect, it, vi } from "vitest";

import getNpmrcPath from "../../../src/utils/get-npmrc-path";
import { join } from "@visulima/path";

const mocks = vi.hoisted(() => {
return {
Expand All @@ -14,8 +15,11 @@ const mocks = vi.hoisted(() => {
};
});

vi.mock("@visulima/fs", () => {
vi.mock("@visulima/fs", async () => {
const actual = await vi.importActual("@visulima/fs");

return {
...actual,
ensureFileSync: mocks.mockedEnsureFileSync,
isAccessibleSync: mocks.mockedIsAccessibleSync,
};
Expand All @@ -27,8 +31,11 @@ vi.mock("@visulima/package", () => {
};
});

vi.mock("@visulima/path", () => {
vi.mock("@visulima/path", async () => {
const actual = await vi.importActual("@visulima/path");

return {
...actual,
resolve: mocks.mockedResolve,
};
});
Expand Down Expand Up @@ -73,10 +80,11 @@ describe("getNpmrcPath", () => {
expect.assertions(3);

const environment = {};
const temporaryNpmrcPath = "/temporary/directory/.npmrc";
const cachePath = "/temporary/directory";
const temporaryNpmrcPath = join(cachePath, ".npmrc");

mocks.mockedIsAccessibleSync.mockReturnValue(false);
mocks.mockedFindCacheDirectorySync.mockReturnValue(temporaryNpmrcPath);
mocks.mockedFindCacheDirectorySync.mockReturnValue(cachePath);

const result = getNpmrcPath(cwd, environment);

Expand Down
8 changes: 5 additions & 3 deletions packages/semantic-release-pnpm/src/utils/get-npmrc-path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ensureFileSync, isAccessibleSync } from "@visulima/fs";
import { findCacheDirectorySync } from "@visulima/package";
import { resolve } from "@visulima/path";
import { join, resolve } from "@visulima/path";

import getError from "./get-error";

Expand All @@ -14,9 +14,11 @@ const getNpmrcPath = (cwd: string, environment: NodeJS.ProcessEnv): string => {
} else if (isAccessibleSync(npmrcPath)) {
npmrc = npmrcPath;
} else {
const temporaryNpmrcPath = findCacheDirectorySync("semantic-release-pnpm", { create: true, cwd });
const cachePath = findCacheDirectorySync("semantic-release-pnpm", { create: true, cwd });

if (cachePath) {
const temporaryNpmrcPath = join(cachePath, ".npmrc");

if (temporaryNpmrcPath) {
ensureFileSync(temporaryNpmrcPath);

npmrc = temporaryNpmrcPath;
Expand Down

0 comments on commit 8f86d0f

Please sign in to comment.