2016-04-12 12:40:37 -04:00
|
|
|
import {
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
inject
|
2016-04-28 20:50:03 -04:00
|
|
|
} from '@angular/core/testing/testing_internal';
|
|
|
|
import {IS_DART} from '../src/facade/lang';
|
|
|
|
import {UrlResolver, createOfflineCompileUrlResolver} from '@angular/compiler/src/url_resolver';
|
2015-02-20 12:00:09 -05:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('UrlResolver', () => {
|
2015-07-27 17:15:02 -04:00
|
|
|
var resolver = new UrlResolver();
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
describe('absolute base url', () => {
|
|
|
|
it('should add a relative path to the base url', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com', 'bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/', 'bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com', './bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/', './bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should replace the base path', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz', 'bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz', './bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should append to the base path', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', 'bar'))
|
|
|
|
.toEqual('http://www.foo.com/baz/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', './bar'))
|
|
|
|
.toEqual('http://www.foo.com/baz/bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support ".." in the path', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', '../bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar'))
|
|
|
|
.toEqual('http://www.foo.com/1/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar'))
|
|
|
|
.toEqual('http://www.foo.com/1/2/biz/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should ignore the base path when the url has a scheme', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com'))
|
|
|
|
.toEqual('http://www.bar.com');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support absolute urls', () => {
|
|
|
|
expect(resolver.resolve('http://www.foo.com', '/bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/', '/bar')).toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz', '/bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
expect(resolver.resolve('http://www.foo.com/baz/', '/bar'))
|
|
|
|
.toEqual('http://www.foo.com/bar');
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
});
|
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
describe('relative base url', () => {
|
2015-06-24 04:27:53 -04:00
|
|
|
it('should add a relative path to the base url', () => {
|
|
|
|
expect(resolver.resolve('foo/', './bar')).toEqual('foo/bar');
|
|
|
|
expect(resolver.resolve('foo/baz', './bar')).toEqual('foo/bar');
|
|
|
|
expect(resolver.resolve('foo/baz', 'bar')).toEqual('foo/bar');
|
2015-06-23 06:05:09 -04:00
|
|
|
|
2015-06-24 04:27:53 -04:00
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
|
2015-06-23 06:05:09 -04:00
|
|
|
it('should support ".." in the path', () => {
|
|
|
|
expect(resolver.resolve('foo/baz', '../bar')).toEqual('bar');
|
|
|
|
expect(resolver.resolve('foo/baz', '../biz/bar')).toEqual('biz/bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support absolute urls', () => {
|
|
|
|
expect(resolver.resolve('foo/baz', '/bar')).toEqual('/bar');
|
|
|
|
expect(resolver.resolve('foo/baz/', '/bar')).toEqual('/bar');
|
|
|
|
});
|
2015-08-08 03:25:24 -04:00
|
|
|
|
2015-12-05 05:21:38 -05:00
|
|
|
it('should not resolve urls against the baseUrl when the url contains a scheme', () => {
|
|
|
|
resolver = new UrlResolver('my_packages_dir');
|
2016-04-12 12:40:37 -04:00
|
|
|
expect(resolver.resolve("base/", 'package:file')).toEqual('my_packages_dir/file');
|
|
|
|
expect(resolver.resolve("base/", 'http:super_file')).toEqual('http:super_file');
|
|
|
|
expect(resolver.resolve("base/", './mega_file')).toEqual('base/mega_file');
|
2015-08-08 03:25:24 -04:00
|
|
|
});
|
|
|
|
});
|
2015-12-05 05:21:38 -05:00
|
|
|
|
2016-01-06 17:13:44 -05:00
|
|
|
describe('packages', () => {
|
|
|
|
it('should resolve a url based on the application package', () => {
|
|
|
|
resolver = new UrlResolver('my_packages_dir');
|
|
|
|
expect(resolver.resolve(null, 'package:some/dir/file.txt'))
|
|
|
|
.toEqual('my_packages_dir/some/dir/file.txt');
|
|
|
|
expect(resolver.resolve(null, 'some/dir/file.txt')).toEqual('some/dir/file.txt');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain a default value of "/packages" when nothing is provided for DART',
|
|
|
|
inject([UrlResolver], (resolver: UrlResolver) => {
|
|
|
|
if (IS_DART) {
|
|
|
|
expect(resolver.resolve(null, 'package:file')).toEqual('/packages/file');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should contain a default value of "/" when nothing is provided for TS/ESM',
|
|
|
|
inject([UrlResolver], (resolver: UrlResolver) => {
|
|
|
|
if (!IS_DART) {
|
|
|
|
expect(resolver.resolve(null, 'package:file')).toEqual('/file');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should resolve a package value when present within the baseurl', () => {
|
|
|
|
resolver = new UrlResolver('/my_special_dir');
|
|
|
|
expect(resolver.resolve('package:some_dir/', 'matias.html'))
|
|
|
|
.toEqual('/my_special_dir/some_dir/matias.html');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('asset urls', () => {
|
|
|
|
var resolver: UrlResolver;
|
|
|
|
beforeEach(() => { resolver = createOfflineCompileUrlResolver(); });
|
|
|
|
|
|
|
|
it('should resolve package: urls into asset: urls', () => {
|
|
|
|
expect(resolver.resolve(null, 'package:somePkg/somePath'))
|
|
|
|
.toEqual('asset:somePkg/lib/somePath');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('corner and error cases', () => {
|
|
|
|
it('should encode URLs before resolving', () => {
|
|
|
|
expect(resolver.resolve('foo/baz', `<p #p>Hello
|
|
|
|
</p>`))
|
|
|
|
.toEqual('foo/%3Cp%20#p%3EHello%0A%20%20%20%20%20%20%20%20%3C/p%3E');
|
|
|
|
});
|
|
|
|
});
|
2015-02-20 12:00:09 -05:00
|
|
|
});
|
|
|
|
}
|