test(ivy): make sure `goog.getMsg()` is defined before being used (#22998)

PR Close #22998
This commit is contained in:
Olivier Combe 2018-03-26 19:05:39 +02:00 committed by Matias Niemelä
parent ab348ee2be
commit d28ce50067
5 changed files with 25 additions and 24 deletions

View File

@ -27,7 +27,7 @@
"name": "HelloWorld" "name": "HelloWorld"
}, },
{ {
"name": "INeedToExistEvenThoughtIAmNotNeeded" "name": "INeedToExistEvenThoughIAmNotNeeded"
}, },
{ {
"name": "Immediate" "name": "Immediate"

View File

@ -14,7 +14,7 @@ export class HelloWorld {
// TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently. // TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently.
@NgModule({declarations: [HelloWorld]}) @NgModule({declarations: [HelloWorld]})
export class INeedToExistEvenThoughtIAmNotNeeded { export class INeedToExistEvenThoughIAmNotNeeded {
} }
// TODO(misko): Package should not be required to make this work. // TODO(misko): Package should not be required to make this work.

View File

@ -14,7 +14,12 @@ ivy_ng_module(
ng_rollup_bundle( ng_rollup_bundle(
name = "bundle", name = "bundle",
# Remove once #22913 lands # TODO(alexeagle): This is inconsistent.
# We try to teach users to always have their workspace at the start of a
# path, to disambiguate from other workspaces.
# Here, the rule implementation is looking in an execroot where the layout
# has an "external" directory for external dependencies.
# This should probably start with "angular/" and let the rule deal with it.
entry_point = "packages/core/test/bundling/hello_world_i18n/index.js", entry_point = "packages/core/test/bundling/hello_world_i18n/index.js",
deps = [ deps = [
":hello_world_i18n", ":hello_world_i18n",
@ -29,8 +34,5 @@ ts_devserver(
":bundle.min.js", ":bundle.min.js",
"index.html", "index.html",
], ],
deps = [ deps = [],
# fix for ibazel until https://github.com/angular/angular/pull/22912 gets merged
"//packages/compiler",
],
) )

View File

@ -8,11 +8,11 @@
<!-- The Angular application will be bootstrapped into this element. --> <!-- The Angular application will be bootstrapped into this element. -->
<hello-world></hello-world> <hello-world></hello-world>
<!-- <!--
Script tag which bootstraps the application. Use `?debug` in URL to select Script tag which bootstraps the application. Use `?debug` in URL to select
the debug version of the script. the debug version of the script.
There are two scripts sources: `bundle.min.js` and `bundle.min_debug.js` You can There are two scripts sources: `bundle.min.js` and `bundle.min_debug.js` You can
switch between which bundle the browser loads to experiment with the application. switch between which bundle the browser loads to experiment with the application.
- `bundle.min.js`: Is what the site would serve to their users. It has gone - `bundle.min.js`: Is what the site would serve to their users. It has gone
@ -23,9 +23,17 @@
property renaming. property renaming.
--> -->
<script> <script>
document.write('<script src="' + // `goog.getMsg()` will be provided by Closure
(document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js') + const translations = {
'"></' + 'script>'); 'Hello World!': 'Bonjour Monde!',
'Hello Title!': 'Bonjour Titre!',
};
window.goog = window.goog || {};
window.goog.getMsg = (key) => translations[key] || key;
document.write('<script src="' +
(document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js') +
'"></' + 'script>');
</script> </script>
</body> </body>
</html> </html>

View File

@ -8,15 +8,6 @@
import {Component, NgModule, ɵrenderComponent as renderComponent} from '@angular/core'; import {Component, NgModule, ɵrenderComponent as renderComponent} from '@angular/core';
// simulate translations for now
const translations: {[key: string]: string} = {
'Hello World!': 'Bonjour Monde!',
'Hello Title!': 'Bonjour Titre!',
};
// simulate Google Closure getMsg for now
(window as any).goog = {getMsg: (key: string) => { return translations[key] || key; }};
@Component({ @Component({
selector: 'hello-world', selector: 'hello-world',
template: `<div i18n i18n-title title="Hello Title!">Hello World!</div>` template: `<div i18n i18n-title title="Hello Title!">Hello World!</div>`
@ -26,7 +17,7 @@ export class HelloWorld {
// TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently. // TODO(misko): Forgetting to export HelloWorld and not having NgModule fails silently.
@NgModule({declarations: [HelloWorld]}) @NgModule({declarations: [HelloWorld]})
export class INeedToExistEvenThoughtIAmNotNeeded { export class INeedToExistEvenThoughIAmNotNeeded {
} }
// TODO(misko): Package should not be required to make this work. // TODO(misko): Package should not be required to make this work.