mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-13 03:35:52 +01:00
14159b31e1
* ref: Relocate utils functions to web pkg * ref: Refactor utils functions * ref: Relocate utils functions to api pkg * ref: Relocate utils functions to config pkg * ref: Relocate utils functions to middleware pkg * ref: Relocate utils functions to storage pkg * ref: relocate utils functions to proxy pkg * ref: relocate utils functions to middleware pkg * ref: refactor utils functions * Fix compilation errors
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { isHTTPProtocol, sortByName } from '../src/web-utils2';
|
|
|
|
describe('Utilities', () => {
|
|
describe('String utilities', () => {
|
|
test('should check HTTP protocol correctly', () => {
|
|
expect(isHTTPProtocol('http://domain.com/-/static/logo.png')).toBeTruthy();
|
|
expect(isHTTPProtocol('https://www.domain.com/-/static/logo.png')).toBeTruthy();
|
|
expect(isHTTPProtocol('//domain.com/-/static/logo.png')).toBeTruthy();
|
|
expect(isHTTPProtocol('file:///home/user/logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('file:///F:/home/user/logo.png')).toBeFalsy();
|
|
// Note that uses ftp protocol in src was deprecated in modern browsers
|
|
expect(isHTTPProtocol('ftp://1.2.3.4/home/user/logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('./logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('.\\logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('../logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('..\\logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('../../static/logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('..\\..\\static\\logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('.logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('/static/logo.png')).toBeFalsy();
|
|
expect(isHTTPProtocol('F:\\static\\logo.png')).toBeFalsy();
|
|
});
|
|
});
|
|
describe('Sort packages', () => {
|
|
const packages = [
|
|
{
|
|
name: 'ghc',
|
|
},
|
|
{
|
|
name: 'abc',
|
|
},
|
|
{
|
|
name: 'zxy',
|
|
},
|
|
];
|
|
test('should order ascending', () => {
|
|
expect(sortByName(packages)).toEqual([
|
|
{
|
|
name: 'abc',
|
|
},
|
|
{
|
|
name: 'ghc',
|
|
},
|
|
{
|
|
name: 'zxy',
|
|
},
|
|
]);
|
|
});
|
|
|
|
test('should order descending', () => {
|
|
expect(sortByName(packages, false)).toEqual([
|
|
{
|
|
name: 'zxy',
|
|
},
|
|
{
|
|
name: 'ghc',
|
|
},
|
|
{
|
|
name: 'abc',
|
|
},
|
|
]);
|
|
});
|
|
});
|
|
});
|