1
0
mirror of https://github.com/SomboChea/ui synced 2026-01-17 00:25:50 +07:00

fix(#300): correctly reference registry url from options

This commit is contained in:
Michael Mok
2019-11-25 02:43:19 +08:00
committed by Priscila Oliveira
parent 0d9232a92c
commit ee74474811
4 changed files with 11 additions and 9 deletions

View File

@@ -17,14 +17,18 @@ describe('utils', () => {
expect(isEmail('')).toBeFalsy();
});
test('getRegistryURL() - should keep slash if location is a sub directory', () => {
test('getRegistryURL() - should not change when location change', () => {
expect(getRegistryURL()).toBe('http://localhost');
history.pushState({}, 'page title', '/-/web/detail');
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
expect(getRegistryURL()).toBe('http://localhost');
history.pushState({}, 'page title', '/');
});
test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
test('getRegistryURL() - should change when UI options change', () => {
expect(getRegistryURL()).toBe('http://localhost');
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost/test';
expect(getRegistryURL()).toBe('http://localhost/test');
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost';
});
});

View File

@@ -15,8 +15,7 @@ export function isEmail(email: string): boolean {
}
export function getRegistryURL(): string {
// Don't add slash if it's not a sub directory
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
return window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
}
export function extractFileName(url: string): string {