2019-01-06 00:50:05 +00:00
|
|
|
import parsePackageURL from '../parsePackageURL';
|
2017-08-05 04:59:44 +00:00
|
|
|
|
2018-12-17 17:38:05 +00:00
|
|
|
describe('parsePackageURL', () => {
|
|
|
|
it('parses plain packages', () => {
|
|
|
|
expect(parsePackageURL('/history@1.0.0/umd/history.min.js')).toEqual({
|
|
|
|
pathname: '/history@1.0.0/umd/history.min.js',
|
|
|
|
search: '',
|
2017-08-05 04:59:44 +00:00
|
|
|
query: {},
|
2018-12-17 17:38:05 +00:00
|
|
|
packageName: 'history',
|
|
|
|
packageVersion: '1.0.0',
|
|
|
|
filename: '/umd/history.min.js'
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-05 04:59:44 +00:00
|
|
|
|
2018-12-17 17:38:05 +00:00
|
|
|
it('parses plain packages with a hyphen in the name', () => {
|
|
|
|
expect(parsePackageURL('/query-string@5.0.0/index.js')).toEqual({
|
|
|
|
pathname: '/query-string@5.0.0/index.js',
|
|
|
|
search: '',
|
2017-08-05 04:59:44 +00:00
|
|
|
query: {},
|
2018-12-17 17:38:05 +00:00
|
|
|
packageName: 'query-string',
|
|
|
|
packageVersion: '5.0.0',
|
|
|
|
filename: '/index.js'
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-05 04:59:44 +00:00
|
|
|
|
2018-12-17 17:38:05 +00:00
|
|
|
it('parses plain packages with no version specified', () => {
|
|
|
|
expect(parsePackageURL('/query-string/index.js')).toEqual({
|
|
|
|
pathname: '/query-string/index.js',
|
|
|
|
search: '',
|
2017-08-05 04:59:44 +00:00
|
|
|
query: {},
|
2018-12-17 17:38:05 +00:00
|
|
|
packageName: 'query-string',
|
|
|
|
packageVersion: 'latest',
|
|
|
|
filename: '/index.js'
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-05 04:59:44 +00:00
|
|
|
|
2018-12-17 17:38:05 +00:00
|
|
|
it('parses plain packages with version spec', () => {
|
|
|
|
expect(parsePackageURL('/query-string@>=4.0.0/index.js')).toEqual({
|
|
|
|
pathname: '/query-string@>=4.0.0/index.js',
|
|
|
|
search: '',
|
2017-08-05 04:59:44 +00:00
|
|
|
query: {},
|
2018-12-17 17:38:05 +00:00
|
|
|
packageName: 'query-string',
|
|
|
|
packageVersion: '>=4.0.0',
|
|
|
|
filename: '/index.js'
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-05 04:59:44 +00:00
|
|
|
|
2018-12-17 17:38:05 +00:00
|
|
|
it('parses scoped packages', () => {
|
|
|
|
expect(parsePackageURL('/@angular/router@4.3.3/src/index.d.ts')).toEqual({
|
|
|
|
pathname: '/@angular/router@4.3.3/src/index.d.ts',
|
|
|
|
search: '',
|
2017-08-05 04:59:44 +00:00
|
|
|
query: {},
|
2018-12-17 17:38:05 +00:00
|
|
|
packageName: '@angular/router',
|
|
|
|
packageVersion: '4.3.3',
|
|
|
|
filename: '/src/index.d.ts'
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-05 04:59:44 +00:00
|
|
|
|
2018-12-17 17:38:05 +00:00
|
|
|
it('parses package names with a period in them', () => {
|
|
|
|
expect(parsePackageURL('/index.js')).toEqual({
|
|
|
|
pathname: '/index.js',
|
|
|
|
search: '',
|
2017-08-05 04:59:44 +00:00
|
|
|
query: {},
|
2018-12-17 17:38:05 +00:00
|
|
|
packageName: 'index.js',
|
|
|
|
packageVersion: 'latest',
|
|
|
|
filename: ''
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-05 04:59:44 +00:00
|
|
|
|
2018-12-17 17:38:05 +00:00
|
|
|
it('parses valid query parameters', () => {
|
|
|
|
expect(parsePackageURL('/history?main=browser')).toEqual({
|
|
|
|
pathname: '/history',
|
|
|
|
search: '?main=browser',
|
|
|
|
query: { main: 'browser' },
|
|
|
|
packageName: 'history',
|
|
|
|
packageVersion: 'latest',
|
|
|
|
filename: ''
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|