Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
17 changes: 16 additions & 1 deletion src/utils/cli-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SyntheticEvent } from 'react';

import { copyToClipBoardUtility } from './cli-utils';
import { copyToClipBoardUtility, getCLISetConfigRegistry } from './cli-utils';

describe('copyToClipBoardUtility', () => {
let originalGetSelection;
Expand Down Expand Up @@ -47,3 +47,18 @@ describe('copyToClipBoardUtility', () => {
expect(spys.removeChild).toHaveBeenCalledWith(expectedDiv);
});
});

describe('getCLISetRegistry', () => {
const command = 'npm set';
const scope = '@testscope';
const blankScope = '';
const url = 'https://test.local';

test('should return ":" separated string when scope is set', () => {
expect(getCLISetConfigRegistry(command, scope, url)).toEqual(`${command} ${scope}:registry ${url}`);
});

test('should not output scope when scope is not set', () => {
expect(getCLISetConfigRegistry(command, blankScope, url)).toEqual(`${command} registry ${url}`);
});
});
3 changes: 2 additions & 1 deletion src/utils/cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const copyToClipBoardUtility = (str: string): ((e: SyntheticEvent<HTMLEle
};

export function getCLISetConfigRegistry(command: string, scope: string, registryUrl: string): string {
return `${command} ${scope}registry ${registryUrl}`;
// if there is a scope defined there needs to be a ":" separator between the scope and the registry
return `${command} ${scope}${scope !== '' ? ':' : ''}registry ${registryUrl}`;
}

export function getCLISetRegistry(command: string, registryUrl: string): string {
Expand Down