Skip to content

Commit

Permalink
fix: throw useful error on missing platform module.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Aug 2, 2016
1 parent 8c8754e commit 73f02c7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 47 deletions.
Expand Up @@ -684,7 +684,7 @@ export function main() {
expect(elAst.providers[0].providers).toEqual([dirProvider]);
});

it('should throw if mixing multi and non multi providers', () => {
it('if mixing multi and non multi providers', () => {
var provider0 = createProvider('service0');
var provider1 = createProvider('service0', {multi: true});
var dirA = createDir('[dirA]', {providers: [provider0]});
Expand Down
5 changes: 4 additions & 1 deletion modules/@angular/core/src/application_ref.ts
Expand Up @@ -313,7 +313,10 @@ export class PlatformRef_ extends PlatformRef {
const ngZoneInjector =
ReflectiveInjector.resolveAndCreate([{provide: NgZone, useValue: ngZone}], this.injector);
const moduleRef = moduleFactory.create(ngZoneInjector);
const exceptionHandler: ExceptionHandler = moduleRef.injector.get(ExceptionHandler);
const exceptionHandler: ExceptionHandler = moduleRef.injector.get(ExceptionHandler, null);
if (!exceptionHandler) {
throw new Error('No ExceptionHandler. Is platform module (BrowserModule) included?');
}
ObservableWrapper.subscribe(ngZone.onError, (error: NgZoneError) => {
exceptionHandler.call(error.error, error.stackTrace);
});
Expand Down
12 changes: 12 additions & 0 deletions modules/@angular/core/test/application_ref_spec.ts
Expand Up @@ -141,6 +141,18 @@ export function main() {
expect(errorLogger.res).toEqual(['EXCEPTION: Test']);
});
}));

it('should throw useful error when ApplicationRef is not configured', async(() => {
@NgModule()
class EmptyModule {
}

return defaultPlatform.bootstrapModule(EmptyModule)
.then(() => fail('expecting error'), (error) => {
expect(error.message)
.toEqual('No ExceptionHandler. Is platform module (BrowserModule) included?');
});
}));
});

describe('bootstrapModuleFactory', () => {
Expand Down
97 changes: 52 additions & 45 deletions tools/tsc-watch/index.ts
Expand Up @@ -65,54 +65,61 @@ const BaseConfig = {
};

if (platform == 'node') {
tscWatch = new TscWatch(Object.assign({
tsconfig: 'modules/tsconfig.json',
onChangeCmds: [
processOutputEmitterCodeGen,
[
'node', 'dist/tools/cjs-jasmine', '--', '{@angular,benchpress}/**/*_spec.js',
'@angular/compiler-cli/test/**/*_spec.js'
]
]
}, BaseConfig));
tscWatch = new TscWatch(Object.assign(

This comment has been minimized.

Copy link
@tbosch

tbosch Aug 2, 2016

Contributor

I am not sure this is correctly formatted...

{
tsconfig: 'modules/tsconfig.json',
onChangeCmds: [
processOutputEmitterCodeGen,
[
'node', 'dist/tools/cjs-jasmine', '--', '{@angular,benchpress}/**/*_spec.js',
'@angular/compiler-cli/test/**/*_spec.js'
]
]
},
BaseConfig));
} else if (platform == 'browser') {
tscWatch = new TscWatch(Object.assign({
tsconfig: 'modules/tsconfig.json',
onStartCmds: [
[
'node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', '--port=9876',
'karma-js.conf.js'
],
[
'node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', '--port=9877',
'modules/@angular/router/karma.conf.js'
],
],
onChangeCmds: [
['node', 'node_modules/karma/bin/karma', 'run', 'karma-js.conf.js', '--port=9876'],
['node', 'node_modules/karma/bin/karma', 'run', '--port=9877'],
]
}, BaseConfig));
tscWatch = new TscWatch(Object.assign(
{
tsconfig: 'modules/tsconfig.json',
onStartCmds: [
[
'node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', '--port=9876',
'karma-js.conf.js'
],
[
'node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', '--port=9877',
'modules/@angular/router/karma.conf.js'
],
],
onChangeCmds: [
['node', 'node_modules/karma/bin/karma', 'run', 'karma-js.conf.js', '--port=9876'],
['node', 'node_modules/karma/bin/karma', 'run', '--port=9877'],
]
},
BaseConfig));
} else if (platform == 'browserNoRouter') {
tscWatch = new TscWatch(Object.assign({
tsconfig: 'modules/tsconfig.json',
onStartCmds: [
[
'node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', '--port=9876',
'karma-js.conf.js'
]
],
onChangeCmds: [
['node', 'node_modules/karma/bin/karma', 'run', 'karma-js.conf.js', '--port=9876'],
]
}, BaseConfig));
tscWatch = new TscWatch(Object.assign(
{
tsconfig: 'modules/tsconfig.json',
onStartCmds: [[
'node', 'node_modules/karma/bin/karma', 'start', '--no-auto-watch', '--port=9876',
'karma-js.conf.js'
]],
onChangeCmds: [
['node', 'node_modules/karma/bin/karma', 'run', 'karma-js.conf.js', '--port=9876'],
]
},
BaseConfig));
} else if (platform == 'tools') {
tscWatch = new TscWatch(Object.assign({
tsconfig: 'tools/tsconfig.json',
onChangeCmds: [[
'node', 'dist/tools/cjs-jasmine/index-tools', '--', '@angular/tsc-wrapped/**/*{_,.}spec.js'
]]
}, BaseConfig));
tscWatch = new TscWatch(Object.assign(
{
tsconfig: 'tools/tsconfig.json',
onChangeCmds: [[
'node', 'dist/tools/cjs-jasmine/index-tools', '--',
'@angular/tsc-wrapped/**/*{_,.}spec.js'
]]
},
BaseConfig));
} else {
throw new Error(`unknown platform: ${platform}`);
}
Expand Down

0 comments on commit 73f02c7

Please sign in to comment.