Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ const DEFAULT_CONFIG: SystemJsNgModuleLoaderConfig = {
export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
private _config: SystemJsNgModuleLoaderConfig;

/**
* @internal
*/
_system: any;

constructor(private _compiler: Compiler, @Optional() config?: SystemJsNgModuleLoaderConfig) {
this._system = () => System;
this._config = config || DEFAULT_CONFIG;
}

Expand All @@ -67,8 +61,7 @@ export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
let [module, exportName] = path.split(_SEPARATOR);
if (exportName === undefined) exportName = 'default';

return this._system()
.import(module)
return System.import(module)
.then((module: any) => module[exportName])
.then((type: any) => checkNotEmpty(type, module, exportName))
.then((type: any) => this._compiler.compileModuleAsync(type));
Expand All @@ -82,8 +75,7 @@ export class SystemJsNgModuleLoader implements NgModuleFactoryLoader {
factoryClassSuffix = '';
}

return this._system()
.import(this._config.factoryPathPrefix + module + this._config.factoryPathSuffix)
return System.import(this._config.factoryPathPrefix + module + this._config.factoryPathSuffix)
.then((module: any) => module[exportName + factoryClassSuffix])
.then((factory: any) => checkNotEmpty(factory, module, exportName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,48 @@
* found in the LICENSE file at https://angular.io/license
*/

import {global} from '@angular/common/src/facade/lang';
import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
import {async, tick} from '@angular/core/testing';
import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal';
import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal';

function mockSystem(module: string, contents: any) {
function mockSystem(modules: {[module: string]: any}) {
return {
'import': (target: string) => {
expect(target).toBe(module);
return Promise.resolve(contents);
expect(modules[target]).not.toBe(undefined);
return Promise.resolve(modules[target]);
}
};
}

export function main() {
describe('SystemJsNgModuleLoader', () => {
let oldSystem: any = null;
beforeEach(() => {
oldSystem = (global as any).System;
(global as any).System = mockSystem({
'test.ngfactory':
{'default': 'test module factory', 'NamedNgFactory': 'test NamedNgFactory'},
'prefixed/test/suffixed': {'NamedNgFactory': 'test module factory'}
});
});
afterEach(() => { (global as any).System = oldSystem; });

it('loads a default factory by appending the factory suffix', async(() => {
let loader = new SystemJsNgModuleLoader(new Compiler());
loader._system = () => mockSystem('test.ngfactory', {'default': 'test module factory'});
loader.load('test').then(contents => { expect(contents).toBe('test module factory'); });
}));
it('loads a named factory by appending the factory suffix', async(() => {
let loader = new SystemJsNgModuleLoader(new Compiler());
loader._system = () =>
mockSystem('test.ngfactory', {'NamedNgFactory': 'test module factory'});
loader.load('test#Named').then(contents => {
expect(contents).toBe('test module factory');
expect(contents).toBe('test NamedNgFactory');
});
}));
it('loads a named factory with a configured prefix and suffix', async(() => {
let loader = new SystemJsNgModuleLoader(new Compiler(), {
factoryPathPrefix: 'prefixed/',
factoryPathSuffix: '/suffixed',
});
loader._system = () =>
mockSystem('prefixed/test/suffixed', {'NamedNgFactory': 'test module factory'});
loader.load('test#Named').then(contents => {
expect(contents).toBe('test module factory');
});
Expand Down