refactor: move angular source to /packages rather than modules/@angular

This commit is contained in:
Jason Aden
2017-03-02 10:48:42 -08:00
parent 5ad5301a3e
commit 3e51a19983
1051 changed files with 18 additions and 18 deletions

View File

@ -0,0 +1,11 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export function setTemplateCache(cache: any /** TODO #9100 */): void {
(<any>window).$templateCache = cache;
}

View File

@ -0,0 +1,84 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ResourceLoader, UrlResolver} from '@angular/compiler';
import {Component} from '@angular/core';
import {TestBed, async, fakeAsync, tick} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/matchers';
import {CachedResourceLoader} from '../../src/resource_loader/resource_loader_cache';
import {setTemplateCache} from './resource_loader_cache_setter';
export function main() {
describe('CachedResourceLoader', () => {
let resourceLoader: CachedResourceLoader;
function createCachedResourceLoader(): CachedResourceLoader {
setTemplateCache({'test.html': '<div>Hello</div>'});
return new CachedResourceLoader();
}
beforeEach(fakeAsync(() => {
TestBed.configureCompiler({
providers: [
{provide: UrlResolver, useClass: TestUrlResolver},
{provide: ResourceLoader, useFactory: createCachedResourceLoader}
]
});
TestBed.configureTestingModule({declarations: [TestComponent]});
TestBed.compileComponents();
}));
it('should throw exception if $templateCache is not found', () => {
setTemplateCache(null);
expect(() => {
resourceLoader = new CachedResourceLoader();
}).toThrowError('CachedResourceLoader: Template cache was not found in $templateCache.');
});
it('should resolve the Promise with the cached file content on success', async(() => {
setTemplateCache({'test.html': '<div>Hello</div>'});
resourceLoader = new CachedResourceLoader();
resourceLoader.get('test.html').then((text) => { expect(text).toBe('<div>Hello</div>'); });
}));
it('should reject the Promise on failure', async(() => {
resourceLoader = new CachedResourceLoader();
resourceLoader.get('unknown.html')
.then((text) => { throw new Error('Not expected to succeed.'); })
.catch((error) => {/** success */});
}));
it('should allow fakeAsync Tests to load components with templateUrl synchronously',
fakeAsync(() => {
TestBed.configureTestingModule({declarations: [TestComponent]});
TestBed.compileComponents();
tick();
const fixture = TestBed.createComponent(TestComponent);
// This should initialize the fixture.
tick();
expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
}));
});
}
@Component({selector: 'test-cmp', templateUrl: 'test.html'})
class TestComponent {
}
class TestUrlResolver extends UrlResolver {
resolve(baseUrl: string, url: string): string {
// Don't use baseUrl to get the same URL as templateUrl.
// This is to remove any difference between Dart and TS tests.
return url;
}
}

View File

@ -0,0 +1,44 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
import {ResourceLoaderImpl} from '../../src/resource_loader/resource_loader_impl';
export function main() {
describe('ResourceLoaderImpl', () => {
let resourceLoader: ResourceLoaderImpl;
// TODO(juliemr): This file currently won't work with dart unit tests run using
// exclusive it or describe (iit or ddescribe). This is because when
// pub run test is executed against this specific file the relative paths
// will be relative to here, so url200 should look like
// static_assets/200.html.
// We currently have no way of detecting this.
const url200 = '/base/modules/@angular/platform-browser/test/browser/static_assets/200.html';
const url404 = '/bad/path/404.html';
beforeEach(() => { resourceLoader = new ResourceLoaderImpl(); });
it('should resolve the Promise with the file content on success',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
resourceLoader.get(url200).then((text) => {
expect(text.trim()).toEqual('<p>hey</p>');
async.done();
});
}), 10000);
it('should reject the Promise on failure',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
resourceLoader.get(url404).catch((e) => {
expect(e).toEqual(`Failed to load ${url404}`);
async.done();
return null;
});
}), 10000);
});
}