Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit 348442b

Browse files
Revert "fix(#300): correctly reference registry url from options"
This reverts commit ee74474.
1 parent ee74474 commit 348442b

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

jest/jestEnvironment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
jest.requireActual('babel/polyfill');
1+
require.requireActual('babel/polyfill');

jest/setup.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { configure } from 'enzyme';
77
import Adapter from 'enzyme-adapter-react-16';
88
import { GlobalWithFetchMock } from 'jest-fetch-mock';
99

10+
// @ts-ignore : Only a void function can be called with the 'new' keyword
1011
configure({ adapter: new Adapter() });
1112

1213
// @ts-ignore : Property '__APP_VERSION__' does not exist on type 'Global'.
1314
global.__APP_VERSION__ = '1.0.0';
1415
// @ts-ignore : Property '__VERDACCIO_BASENAME_UI_OPTIONS' does not exist on type 'Global'.
15-
global.__VERDACCIO_BASENAME_UI_OPTIONS = { base: 'http://localhost' };
16-
// @ts-ignore : Property 'VERDACCIO_API_URL' does not exist on type 'Global'.
16+
global.__VERDACCIO_BASENAME_UI_OPTIONS = {};
17+
1718
global.VERDACCIO_API_URL = 'https://verdaccio.tld';
1819

1920
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;

src/utils/url.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ describe('utils', () => {
1717
expect(isEmail('')).toBeFalsy();
1818
});
1919

20-
test('getRegistryURL() - should not change when location change', () => {
21-
expect(getRegistryURL()).toBe('http://localhost');
20+
test('getRegistryURL() - should keep slash if location is a sub directory', () => {
2221
history.pushState({}, 'page title', '/-/web/detail');
23-
expect(getRegistryURL()).toBe('http://localhost');
22+
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
2423
history.pushState({}, 'page title', '/');
2524
});
2625

27-
test('getRegistryURL() - should change when UI options change', () => {
26+
test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
2827
expect(getRegistryURL()).toBe('http://localhost');
29-
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost/test';
30-
expect(getRegistryURL()).toBe('http://localhost/test');
31-
window.__VERDACCIO_BASENAME_UI_OPTIONS.base = 'http://localhost';
3228
});
3329
});
3430

src/utils/url.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export function isEmail(email: string): boolean {
1515
}
1616

1717
export function getRegistryURL(): string {
18-
return window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
18+
// Don't add slash if it's not a sub directory
19+
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
1920
}
2021

2122
export function extractFileName(url: string): string {

0 commit comments

Comments
 (0)