-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54c939e
commit 427619c
Showing
3 changed files
with
44 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { parseProjectNpmrc } from "./parseProjectNpmrc.js"; | ||
|
||
const mockReadFile = vi.fn(); | ||
|
||
vi.mock("./shared/readFileSafe.js", () => ({ | ||
get readFileSafe() { | ||
return mockReadFile; | ||
}, | ||
})); | ||
|
||
describe("parseProjectNpmrc", () => { | ||
it("outputs the expected structure on successful parse", async () => { | ||
mockReadFile.mockResolvedValue(`registry=https://pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/ | ||
always-auth=true`); | ||
const result = await parseProjectNpmrc({ | ||
npmrcPath: "/home/john/code/github/ado-npm-auth-lite/.npmrc", | ||
}); | ||
expect(result).toEqual({ | ||
organisation: "johnnyreilly", | ||
urlWithoutRegistryAtEnd: | ||
"//pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/", | ||
urlWithoutRegistryAtStart: | ||
"//pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/", | ||
}); | ||
}); | ||
|
||
it("errors on invalid content", async () => { | ||
mockReadFile.mockResolvedValue(`stuff`); | ||
await expect(() => | ||
parseProjectNpmrc({ | ||
npmrcPath: "/home/john/code/github/ado-npm-auth-lite/.npmrc", | ||
}), | ||
).rejects.toThrowError("Unable to extract information from project .npmrc"); | ||
}); | ||
}); |
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