Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publish): Use APIs for validation queries instead of CLI
This removes the `--no-verify-registry` flag, as the former code path is no longer called, having been replaced with a far more robust login validation.
- Loading branch information
Showing
32 changed files
with
319 additions
and
337 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,63 @@ | ||
"use strict"; | ||
|
||
jest.mock("npm-registry-fetch"); | ||
|
||
const fetch = require("npm-registry-fetch"); | ||
const getNpmUsername = require("../lib/get-npm-username"); | ||
|
||
fetch.json.mockImplementation(() => Promise.resolve({ username: "lerna-test" })); | ||
|
||
describe("getNpmUsername", () => { | ||
const origConsoleError = console.error; | ||
|
||
beforeEach(() => { | ||
console.error = jest.fn(); | ||
}); | ||
|
||
afterEach(() => { | ||
console.error = origConsoleError; | ||
}); | ||
|
||
test("fetches whoami endpoint", async () => { | ||
const opts = { such: "npm-conf", wow: true }; | ||
|
||
const username = await getNpmUsername(opts); | ||
|
||
expect(username).toBe("lerna-test"); | ||
expect(fetch.json).lastCalledWith("-/whoami", opts); | ||
}); | ||
|
||
test("throws an error when successful fetch yields empty username", async () => { | ||
fetch.json.mockImplementationOnce(() => Promise.resolve({ username: undefined })); | ||
|
||
try { | ||
await getNpmUsername({ stub: true }); | ||
} catch (err) { | ||
expect(err.prefix).toBe("ENEEDAUTH"); | ||
expect(err.message).toBe("You must be logged in to publish packages. Use `npm login` and try again."); | ||
expect(console.error).not.toBeCalled(); | ||
} | ||
|
||
expect.assertions(3); | ||
}); | ||
|
||
test("logs failure message before throwing validation error", async () => { | ||
fetch.json.mockImplementationOnce(() => { | ||
const err = new Error("whoops"); | ||
|
||
err.code = "E500"; | ||
|
||
return Promise.reject(err); | ||
}); | ||
|
||
try { | ||
await getNpmUsername({ stub: true }); | ||
} catch (err) { | ||
expect(err.prefix).toBe("EWHOAMI"); | ||
expect(err.message).toBe("Authentication error. Use `npm whoami` to troubleshoot."); | ||
expect(console.error).toBeCalledWith("whoops"); | ||
} | ||
|
||
expect.assertions(3); | ||
}); | ||
}); |
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
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
Oops, something went wrong.