-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
119 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const { detectNpm, detectPnpm } = require("../lib/narn-lib"); | ||
const fs = require("fs"); | ||
|
||
jest.mock("fs", () => ({ | ||
access: jest.fn(), | ||
constants: { | ||
F_OK: 1 | ||
} | ||
})); | ||
|
||
describe("package manager detection", () => { | ||
beforeEach(() => { | ||
fs.access.mockReset(); | ||
}); | ||
|
||
it("properly detects pnpm packages", async () => { | ||
fs.access.mockImplementationOnce((path, mode, errBack) => { | ||
if (path.includes("pnpm-lock.yaml")) { | ||
errBack(false); | ||
} else { | ||
errBack(true); | ||
} | ||
}); | ||
const isPnpm = await detectPnpm(["add", "[email protected]"]); | ||
expect(isPnpm).toBe(true); | ||
}); | ||
|
||
it("properly detects pnpm packages", async () => { | ||
fs.access.mockImplementationOnce((path, mode, errBack) => { | ||
if (path.includes("package-lock.json")) { | ||
errBack(false); | ||
} else { | ||
errBack(true); | ||
} | ||
}); | ||
const isNpm = await detectNpm(["add", "[email protected]"]); | ||
expect(isNpm).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const { detectYarn } = require("../lib/narn-lib"); | ||
const { detectNpm } = require("../lib/narn-lib"); | ||
const fs = require("fs"); | ||
|
||
jest.mock("fs", () => ({ | ||
|
@@ -14,20 +14,20 @@ describe("narn global commands", () => { | |
}); | ||
|
||
it("supports installing global packages", async () => { | ||
const isYarn = await detectYarn(["global", "add", "[email protected]"]); | ||
expect(isYarn).toBe(true); | ||
const isNpm = await detectNpm(["global", "add", "[email protected]"]); | ||
expect(isNpm).toBe(false); | ||
}); | ||
|
||
it("supports uninstalling global packages", async () => { | ||
const isYarn = await detectYarn(["global", "remove", "lodash"]); | ||
expect(isYarn).toBe(true); | ||
const isNpm = await detectNpm(["global", "remove", "lodash"]); | ||
expect(isNpm).toBe(false); | ||
}); | ||
|
||
it("doesn't think everything is global", async () => { | ||
fs.access.mockImplementationOnce((path, mode, errBack) => { | ||
errBack(false); | ||
}); | ||
const isYarn = await detectYarn(["add", "[email protected]"]); | ||
expect(isYarn).toBe(false); | ||
const isNpm = await detectNpm(["add", "[email protected]"]); | ||
expect(isNpm).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters