mirror of https://github.com/nodejs/corepack.git
test: add more test
This commit is contained in:
parent
1435643a31
commit
b6b489ab80
|
|
@ -1314,6 +1314,30 @@ it(`should download latest pnpm from custom registry`, async () => {
|
|||
});
|
||||
});
|
||||
|
||||
it(`should download from npm registry url by default`, async () => {
|
||||
await xfs.mktempPromise(async cwd => {
|
||||
process.env.npm_config_registry = `https://registry.npmmirror.com`;
|
||||
process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT = `1`;
|
||||
|
||||
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
|
||||
packageManager: `pnpm@10.1.0`,
|
||||
});
|
||||
|
||||
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
|
||||
exitCode: 0,
|
||||
stdout: `10.1.0\n`,
|
||||
stderr: `! Corepack is about to download https://registry.npmmirror.com/pnpm/-/pnpm-10.1.0.tgz\n`,
|
||||
});
|
||||
|
||||
// Should keep working with cache
|
||||
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
|
||||
exitCode: 0,
|
||||
stdout: `10.1.0\n`,
|
||||
stderr: ``,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
|
||||
beforeEach(() => {
|
||||
process.env.AUTH_TYPE = `COREPACK_NPM_TOKEN`; // See `_registryServer.mjs`
|
||||
|
|
|
|||
|
|
@ -36,6 +36,15 @@ describe(`npm registry utils fetchAsJson`, () => {
|
|||
expect(httpFetchAsJson).lastCalledWith(`${process.env.COREPACK_NPM_REGISTRY}/package-name`, {headers: DEFAULT_HEADERS});
|
||||
});
|
||||
|
||||
it(`loads from npm registry url`, async () => {
|
||||
// `process.env` is reset after each tests in setupTests.js.
|
||||
process.env.npm_config_registry = `https://registry.example.org`;
|
||||
await fetchAsJson(`package-name`);
|
||||
|
||||
expect(httpFetchAsJson).toBeCalled();
|
||||
expect(httpFetchAsJson).lastCalledWith(`${process.env.npm_config_registry}/package-name`, {headers: DEFAULT_HEADERS});
|
||||
});
|
||||
|
||||
it(`adds authorization header with bearer token if COREPACK_NPM_TOKEN is set`, async () => {
|
||||
// `process.env` is reset after each tests in setupTests.js.
|
||||
process.env.COREPACK_NPM_TOKEN = `foo`;
|
||||
|
|
@ -50,6 +59,20 @@ describe(`npm registry utils fetchAsJson`, () => {
|
|||
}});
|
||||
});
|
||||
|
||||
it(`uses npm registry url if COREPACK_NPM_TOKEN is set`, async () => {
|
||||
// `process.env` is reset after each tests in setupTests.js.
|
||||
process.env.COREPACK_NPM_TOKEN = `foo`;
|
||||
process.env.npm_config_registry = `https://registry.example.org`;
|
||||
|
||||
await fetchAsJson(`package-name`);
|
||||
|
||||
expect(httpFetchAsJson).toBeCalled();
|
||||
expect(httpFetchAsJson).lastCalledWith(`${process.env.npm_config_registry}/package-name`, {headers: {
|
||||
...DEFAULT_HEADERS,
|
||||
authorization: `Bearer ${process.env.COREPACK_NPM_TOKEN}`,
|
||||
}});
|
||||
});
|
||||
|
||||
it(`only adds authorization header with bearer token if COREPACK_NPM_TOKEN and COREPACK_NPM_USERNAME are set`, async () => {
|
||||
// `process.env` is reset after each tests in setupTests.js.
|
||||
process.env.COREPACK_NPM_TOKEN = `foo`;
|
||||
|
|
|
|||
Loading…
Reference in New Issue