Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: fix testing error
  • Loading branch information
zanminkian committed Apr 14, 2025
commit 1435643a31062c3a85a68cb37b90d49a7561a007
7 changes: 6 additions & 1 deletion tests/npmRegistryUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe(`npm registry utils fetchAsJson`, () => {
});

it(`loads from DEFAULT_NPM_REGISTRY_URL by default`, async () => {
process.env.npm_config_registry = `https://registry.npmjs.org`;
await fetchAsJson(`package-name`);

expect(httpFetchAsJson).toBeCalled();
Expand All @@ -38,6 +39,7 @@ describe(`npm registry utils fetchAsJson`, () => {
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`;
process.env.npm_config_registry = `https://registry.npmjs.org`;

await fetchAsJson(`package-name`);

Expand All @@ -53,6 +55,7 @@ describe(`npm registry utils fetchAsJson`, () => {
process.env.COREPACK_NPM_TOKEN = `foo`;
process.env.COREPACK_NPM_USERNAME = `bar`;
process.env.COREPACK_NPM_PASSWORD = `foobar`;
process.env.npm_config_registry = `https://registry.npmjs.org`;

await fetchAsJson(`package-name`);

Expand All @@ -68,6 +71,7 @@ describe(`npm registry utils fetchAsJson`, () => {
// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_NPM_USERNAME = `foo`;
process.env.COREPACK_NPM_PASSWORD = `bar`;
process.env.npm_config_registry = `https://registry.npmjs.org`;

const encodedCreds = Buffer.from(`${process.env.COREPACK_NPM_USERNAME}:${process.env.COREPACK_NPM_PASSWORD}`, `utf8`).toString(`base64`);

Expand All @@ -80,9 +84,10 @@ describe(`npm registry utils fetchAsJson`, () => {
}});
});

it(`does not add authorization header if COREPACK_NPM_USERNAME is set and COREPACK_NPM_PASSWORD is not.`, async () => {
it(`does not add authorization header if COREPACK_NPM_USERNAME is set and COREPACK_NPM_PASSWORD is not`, async () => {
// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_NPM_USERNAME = `foo`;
process.env.npm_config_registry = `https://registry.npmjs.org`;

await fetchAsJson(`package-name`);

Expand Down