test(dart/transform): Update unit tests to expect code in <file>.template.dart

Closes #6711
This commit is contained in:
Tim Blasi 2016-01-26 16:36:13 -08:00 committed by Timothy Blasi
parent 8c36aa866a
commit 566d3ede04
31 changed files with 148 additions and 143 deletions

View File

@ -73,6 +73,17 @@ class TransformerOptions {
/// at any time.
final bool lazyTransformers;
/// Whether to generate compiled templates.
///
/// This option is strictly for internal testing and is not available as an
/// option on the transformer.
/// Setting this to `false` means that our generated .template.dart files do
/// not have any compiled templates or change detectors defined in them.
/// These files will not be usable, but this allows us to test the code output
/// of the transformer without breaking when compiled template internals
/// change.
final bool genCompiledTemplates;
TransformerOptions._internal(
this.entryPoints,
this.entryPointGlobs,
@ -80,13 +91,14 @@ class TransformerOptions {
this.mirrorMode,
this.initReflector,
this.annotationMatcher,
{this.genChangeDetectionDebugInfo,
this.reflectPropertiesAsAttributes,
this.platformDirectives,
this.platformPipes,
{this.formatCode,
this.genChangeDetectionDebugInfo,
this.genCompiledTemplates,
this.inlineViews,
this.lazyTransformers,
this.formatCode});
this.platformDirectives,
this.platformPipes,
this.reflectPropertiesAsAttributes});
factory TransformerOptions(List<String> entryPoints,
{String modeName: 'release',
@ -95,6 +107,7 @@ class TransformerOptions {
List<ClassDescriptor> customAnnotationDescriptors: const [],
bool inlineViews: false,
bool genChangeDetectionDebugInfo: false,
bool genCompiledTemplates: true,
bool reflectPropertiesAsAttributes: false,
List<String> platformDirectives,
List<String> platformPipes,
@ -108,6 +121,7 @@ class TransformerOptions {
return new TransformerOptions._internal(entryPoints, entryPointGlobs,
modeName, mirrorMode, initReflector, annotationMatcher,
genChangeDetectionDebugInfo: genChangeDetectionDebugInfo,
genCompiledTemplates: genCompiledTemplates,
reflectPropertiesAsAttributes: reflectPropertiesAsAttributes,
platformDirectives: platformDirectives,
platformPipes: platformPipes,

View File

@ -4,6 +4,7 @@ import 'dart:async';
import 'package:barback/barback.dart';
import 'package:angular2/src/compiler/source_module.dart';
import 'package:angular2/src/core/change_detection/interfaces.dart';
import 'package:angular2/src/facade/lang.dart';
import 'package:angular2/src/core/reflection/reflection.dart';

View File

@ -52,16 +52,11 @@ class TemplateCompiler extends Transformer implements LazyTransformer {
if (outputs != null) {
if (outputs.ngDeps != null) {
final buf = new StringBuffer();
final templatesSrc =
options.genCompiledTemplates ? outputs.templatesSource : null;
writeTemplateFile(
new NgDepsWriter(buf), outputs.ngDeps, outputs.templatesSource);
new NgDepsWriter(buf), outputs.ngDeps, templatesSrc);
ngDepsCode = formatter.format(buf.toString());
if (primaryId.path.endsWith('index.ng_meta.json')) {
final buf2 = new StringBuffer();
var writer = new NgDepsWriter(buf2);
outputs.ngDeps.imports.forEach(writer.writeImportModel);
print(buf2.toString());
}
}
}
transform.addOutput(

View File

@ -3,7 +3,7 @@ library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/core/reflection/reflection.dart';
import 'package:angular2/src/core/reflection/reflection_capabilities.dart';
import 'hello.ng_deps.dart' deferred as a; // ng_deps. Should be rewritten.
import 'hello.template.dart' deferred as a; // ng_deps. Should be rewritten.
import 'b.dart' deferred as b; // No ng_deps. Shouldn't be rewritten.
void main() {

View File

@ -3,7 +3,7 @@ library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/core/reflection/reflection.dart';
import 'package:angular2/src/core/reflection/reflection_capabilities.dart';
import 'hello.ng_deps.dart' deferred as a;
import 'hello.template.dart' deferred as a;
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();

View File

@ -130,7 +130,7 @@ void allTests() {
var linked = (await _testLink(reader, fooAssetId)).ngDeps;
expect(linked).toBeNotNull();
var linkedImport = linked.depImports
.firstWhere((i) => i.uri.endsWith('bar.ng_deps.dart'));
.firstWhere((i) => i.uri.endsWith('bar.template.dart'));
expect(linkedImport).toBeNotNull();
expect(linkedImport.prefix.startsWith('i')).toBeTrue();
});
@ -145,7 +145,7 @@ void allTests() {
var linked = (await _testLink(reader, fooAssetId)).ngDeps;
expect(linked).toBeNotNull();
var linkedImport = linked.depImports
.firstWhere((i) => i.uri.endsWith('bar.ng_deps.dart'));
.firstWhere((i) => i.uri.endsWith('bar.template.dart'));
expect(linkedImport).toBeNotNull();
expect(linkedImport.prefix.startsWith('i')).toBeTrue();
});
@ -163,7 +163,7 @@ void allTests() {
var linked = (await _testLink(reader, fooAssetId)).ngDeps;
expect(linked).toBeNotNull();
var linkedImport = linked.depImports.firstWhere(
(i) => i.uri.endsWith('bar.ng_deps.dart'),
(i) => i.uri.endsWith('bar.template.dart'),
orElse: () => null);
expect(linkedImport).toBeNull();
});

View File

@ -13,8 +13,10 @@ main() {
}
var formatter = new DartFormatter();
var transform = new AngularTransformerGroup(
new TransformerOptions(['web/index.dart'], formatCode: true));
var transform = new AngularTransformerGroup(new TransformerOptions(
['web/index.dart'],
formatCode: true,
genCompiledTemplates: false));
// Each test has its own directory for inputs & an `expected` directory for
// expected outputs.
@ -56,10 +58,10 @@ void allTests() {
'a|web/bar.dart': 'simple_annotation_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart':
'simple_annotation_files/expected/bar.ng_deps.dart',
'a|web/index.ng_deps.dart':
'simple_annotation_files/expected/index.ng_deps.dart'
'a|web/bar.template.dart':
'simple_annotation_files/expected/bar.template.dart',
'a|web/index.template.dart':
'simple_annotation_files/expected/index.template.dart'
}),
new IntegrationTestConfig(
'should generate proper code for a Component with multiple deps.',
@ -69,7 +71,7 @@ void allTests() {
'a|web/bar.dart': 'two_deps_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart': 'two_deps_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart': 'two_deps_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should generate proper code for a Component declaring a '
@ -80,7 +82,8 @@ void allTests() {
'a|web/bar.dart': 'list_of_types_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart': 'list_of_types_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart':
'list_of_types_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should generate a factory for a class with no declared ctor.',
@ -89,7 +92,8 @@ void allTests() {
'a|web/bar.dart': 'synthetic_ctor_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart': 'synthetic_ctor_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart':
'synthetic_ctor_files/expected/bar.template.dart'
}),
new IntegrationTestConfig('should preserve multiple annotations.', inputs: {
'a|web/index.dart': 'two_annotations_files/index.dart',
@ -97,8 +101,8 @@ void allTests() {
'angular2|lib/src/core/metadata.dart':
'../../../lib/src/core/metadata.dart'
}, outputs: {
'a|web/bar.ng_deps.dart':
'two_annotations_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart':
'two_annotations_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should generate getters for output events defined on a Component.',
@ -107,7 +111,7 @@ void allTests() {
'a|web/bar.dart': 'event_getter_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart': 'event_getter_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart': 'event_getter_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should handle Directive dependencies declared on a View.',
@ -117,7 +121,8 @@ void allTests() {
'a|web/bar.dart': 'directive_dep_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart': 'directive_dep_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart':
'directive_dep_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should handle chained Directive dependencies declared on a View.',
@ -128,18 +133,20 @@ void allTests() {
'a|web/baz.dart': 'directive_chain_files/baz.dart'
},
outputs: {
'a|web/bar.ng_deps.dart':
'directive_chain_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart':
'directive_chain_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should handle empty ng_deps files that define directive aliases.',
'should handle empty template files that define directive aliases.',
inputs: {
'a|web/foo.dart': 'empty_ng_deps_files/foo.dart',
'a|web/bar.dart': 'empty_ng_deps_files/bar.dart'
},
outputs: {
'a|web/foo.ng_deps.dart': 'empty_ng_deps_files/expected/foo.ng_deps.dart',
'a|web/bar.ng_deps.dart': 'empty_ng_deps_files/expected/bar.ng_deps.dart'
'a|web/foo.template.dart':
'empty_ng_deps_files/expected/foo.template.dart',
'a|web/bar.template.dart':
'empty_ng_deps_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should generate setters for annotated properties.',
@ -147,8 +154,8 @@ void allTests() {
'a|web/bar.dart': 'queries_prop_annotation_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart':
'queries_prop_annotation_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart':
'queries_prop_annotation_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should generate setters for `queries` values in Directives.',
@ -156,14 +163,18 @@ void allTests() {
'a|web/bar.dart': 'queries_class_annotation_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart':
'queries_class_annotation_files/expected/bar.ng_deps.dart'
'a|web/bar.template.dart':
'queries_class_annotation_files/expected/bar.template.dart'
}),
new IntegrationTestConfig(
'should handle @override annotations in properties on Directives.',
inputs: {'a|web/bar.dart': 'override_annotation_files/bar.dart'},
outputs:
{'a|web/bar.ng_deps.dart': 'override_annotation_files/expected/bar.ng_deps.dart'})
inputs: {
'a|web/bar.dart': 'override_annotation_files/bar.dart'
},
outputs: {
'a|web/bar.template.dart':
'override_annotation_files/expected/bar.template.dart'
})
];
var cache = {};
@ -181,6 +192,9 @@ void allTests() {
config.assetPathToExpectedOutputPath.forEach((key, value) {
config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () {
var code = _readFile(value);
if (code == null) {
throw 'Failed to read $value';
}
return value.endsWith('dart') ? formatter.format(code) : code;
});
});
@ -208,8 +222,8 @@ void _testDeferredRewriter() {
inputs.addAll(commonInputs);
inputs.keys.forEach((k) => inputs[k] = _readFile(inputs[k]));
var outputs = {
'a|web/bar.ng_deps.dart':
_readFile('deferred_files/expected/bar.ng_deps.dart'),
'a|web/bar.template.dart':
_readFile('deferred_files/expected/bar.template.dart'),
'a|web/bar.dart': deferredOuts.barContents,
'a|web/index.dart': deferredOuts.indexContents
};

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -17,7 +16,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Component(selector: '[soup]'),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -8,7 +8,7 @@ library angular2.test.transform.integration.deferred;
const indexContents = '''
library web_foo;
import 'index.ng_deps.dart' as ngStaticInit;import 'bar.ng_deps.dart' deferred as bar;
import 'index.template.dart' as ngStaticInit;import 'bar.template.dart' deferred as bar;
void main() {
bar.loadLibrary().then((_) {bar.initReflector();}).then((_) {
@ -22,7 +22,7 @@ library bar;
import 'package:angular2/src/core/metadata.dart';
import 'dep.ng_deps.dart' deferred as dep;
import 'dep.template.dart' deferred as dep;
@Component(selector: '[soup]')
@View(template: '')

View File

@ -1,12 +1,11 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'baz.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'baz.ng_deps.dart' as i1;
import 'package:angular2/src/core/metadata.template.dart' as i0;
import 'baz.template.dart' as i1;
export 'bar.dart';
var _visited = false;
@ -19,7 +18,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Component(selector: 'soup'),
const View(directives: [Foo], template: 'foo'),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -1,12 +1,11 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'foo.dart' as prefix;
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'foo.ng_deps.dart' as i1;
import 'package:angular2/src/core/metadata.template.dart' as i0;
import 'foo.template.dart' as i1;
export 'bar.dart';
var _visited = false;
@ -19,7 +18,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Component(selector: 'soup'),
const View(directives: [prefix.Foo], template: 'foo'),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -1,12 +1,11 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'foo.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.dart';
import 'foo.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'bar.ng_deps.dart' as i1;
import 'package:angular2/src/core/metadata.template.dart' as i0;
import 'bar.template.dart' as i1;
export 'foo.dart';
var _visited = false;
@ -19,7 +18,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Component(selector: '[soup]'),
const View(directives: const [directiveAlias], template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()));
i0.initReflector();
i1.initReflector();

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -19,7 +18,7 @@ void initReflector() {
outputs: ['eventName1', 'eventName2: propName2'],
selector: '[soup]'),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()))
..registerGetters(
{'eventName1': (o) => o.eventName1, 'eventName2': (o) => o.eventName2});

View File

@ -1,11 +1,10 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'foo.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -18,7 +17,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Component(componentServices: const [MyContext]),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [
const [MyContext]
], (MyContext c) => new MyComponent(c)));

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -18,7 +17,7 @@ void initReflector() {
const [
const Component(selector: '[soup]'),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
],
const [],
() => new MyComponent(),

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -19,7 +18,7 @@ void initReflector() {
queries: const {'queryField': const ContentChild('child')},
selector: '[soup]'),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()))
..registerSetters({'queryField': (o, v) => o.queryField = v});
i0.initReflector();

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -18,7 +17,7 @@ void initReflector() {
const [
const Component(selector: '[soup]'),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
],
const [],
() => new MyComponent(),

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -16,7 +15,7 @@ void initReflector() {
MyComponent,
new _ngRef.ReflectionInfo(const [
const Component(selector: '[soup]', template: 'aa'),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -1,11 +1,11 @@
library web_foo.ng_deps.dart;
library web_foo.template.dart;
import 'index.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/bootstrap_static.dart' show bootstrapStatic;
import 'package:angular2/src/core/reflection/reflection.dart';
import 'bar.dart';
import 'bar.ng_deps.dart' as i0;
import 'bar.template.dart' as i0;
export 'index.dart';
var _visited = false;

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -17,7 +16,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Component(selector: '[soup]'),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -1,10 +1,9 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -17,7 +16,7 @@ void initReflector() {
new _ngRef.ReflectionInfo(const [
const Component(selector: '[soup]'),
const View(template: 'Salad: {{myNum}} is awesome'),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
], const [], () => new MyComponent()));
i0.initReflector();
}

View File

@ -1,11 +1,10 @@
library bar.ng_deps.dart;
library bar.template.dart;
import 'bar.dart';
import 'package:angular2/src/core/reflection/reflection.dart' as _ngRef;
import 'package:angular2/src/core/metadata.dart';
import 'foo.dart' as prefix;
import 'bar.template.dart' as _templates;
import 'package:angular2/src/core/metadata.ng_deps.dart' as i0;
import 'package:angular2/src/core/metadata.template.dart' as i0;
export 'bar.dart';
var _visited = false;
@ -19,7 +18,7 @@ void initReflector() {
const [
const Component(selector: 'soup'),
const View(template: ''),
_templates.hostViewFactory_MyComponent
hostViewFactory_MyComponent
],
const [
const [prefix.MyContext],

View File

@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.reflection_remover_files;
var code = """
library web_foo;
import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit;
import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit;
void main() async {
var appRef = await bootstrapStatic(MyComponent, null, () { ngStaticInit.initReflector(); });

View File

@ -11,7 +11,7 @@ library angular2.test.transform.debug_reflection_remover_files;
var code = """
library web_foo;
import 'package:angular2/bootstrap.dart';import 'index.ng_deps.dart' as ngStaticInit;
import 'package:angular2/bootstrap.dart';import 'index.template.dart' as ngStaticInit;
import 'package:angular2/src/core/reflection/reflection.dart';
import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart';

View File

@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.debug_mirrors_files.expected;
var code = """
library web_foo;
import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit;
import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit;
import 'package:angular2/src/core/reflection/reflection.dart';
import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart';

View File

@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.function_annotation_files;
const code = """
library web_foo;
import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit;
import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit;
import 'package:angular2/src/core/reflection/reflection.dart';
/*import 'package:angular2/src/core/reflection/reflection_capabilities.dart';*/

View File

@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.method_annotation_files;
const code = """
library web_foo;
import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit;
import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit;
class TestBootstrapper {
@AngularEntrypoint("Method entrypoint")

View File

@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.reflection_remover_files;
var code = """
library web_foo;
import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit;
import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit;
import 'package:angular2/src/core/reflection/reflection.dart';
/*import 'package:angular2/src/core/reflection/reflection_capabilities.dart';*/

View File

@ -11,7 +11,7 @@ library angular2.test.transform.reflection_remover.verbose_files.expected;
var code = """
library web_foo;
import 'package:angular2/bootstrap_static.dart';import 'index.ng_deps.dart' as ngStaticInit;
import 'package:angular2/bootstrap_static.dart';import 'index.template.dart' as ngStaticInit;
import 'package:angular2/src/core/reflection/reflection.dart';
import 'package:angular2/src/core/reflection/debug_reflection_capabilities.dart';

View File

@ -11,8 +11,10 @@ import 'package:guinness/guinness.dart';
import 'package:angular2/src/core/change_detection/codegen_name_util.dart'
show CONTEXT_ACCESSOR;
import 'package:angular2/src/platform/server/html_adapter.dart';
import 'package:angular2/src/transform/template_compiler/generator.dart';
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
import 'package:angular2/src/transform/common/code/source_module.dart';
import 'package:angular2/src/transform/common/zone.dart' as zone;
import 'package:angular2/src/transform/template_compiler/generator.dart';
import '../common/compile_directive_metadata/ng_for.ng_meta.dart' as ngMeta;
import '../common/ng_meta_helper.dart';
@ -109,7 +111,7 @@ void allTests() {
final outputs = await process(fooAssetId);
// TODO(kegluenq): Does this next line need to be updated as well?
expect(outputs.templatesCode).not.toContain('notifyDispatcher');
expect(_generatedCode(outputs)).not.toContain('notifyDispatcher');
});
it('should parse simple expressions in inline templates.', () async {
@ -121,14 +123,11 @@ void allTests() {
final outputs = await process(fooAssetId);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(ngDeps.imports).toContain(new ImportModel()
..uri = 'foo.template.dart'
..prefix = '_templates');
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = '_templates.hostViewFactory_FooComponent'
..name = 'hostViewFactory_FooComponent'
..isConstObject = true);
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toContain('$CONTEXT_ACCESSOR.greeting')
..toContain('$CONTEXT_ACCESSOR.b');
});
@ -142,14 +141,11 @@ void allTests() {
final outputs = await process(fooAssetId);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(ngDeps.imports).toContain(new ImportModel()
..uri = 'foo.template.dart'
..prefix = '_templates');
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = '_templates.hostViewFactory_FooComponent'
..name = 'hostViewFactory_FooComponent'
..isConstObject = true);
expect(outputs.templatesCode)..toContain('$CONTEXT_ACCESSOR.action()');
expect(_generatedCode(outputs))..toContain('$CONTEXT_ACCESSOR.action()');
});
it('should parse `View` directives with a single dependency.', () async {
@ -172,15 +168,12 @@ void allTests() {
final outputs = await process(fooAssetId);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(ngDeps.imports).toContain(new ImportModel()
..uri = 'foo.template.dart'
..prefix = '_templates');
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = '_templates.hostViewFactory_FooComponent'
..name = 'hostViewFactory_FooComponent'
..isConstObject = true);
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toContain("import 'bar.dart'")
..toContain("import 'bar.template.dart'");
});
@ -206,15 +199,12 @@ void allTests() {
final outputs = await process(fooAssetId);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(ngDeps.imports).toContain(new ImportModel()
..uri = 'foo.template.dart'
..prefix = '_templates');
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = '_templates.hostViewFactory_FooComponent'
..name = 'hostViewFactory_FooComponent'
..isConstObject = true);
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toContain("import 'bar.dart'")
..toContain("import 'bar.template.dart'");
});
@ -238,15 +228,12 @@ void allTests() {
final outputs = await process(fooAssetId);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(ngDeps.imports).toContain(new ImportModel()
..uri = 'foo.template.dart'
..prefix = '_templates');
expect(ngDeps.reflectables.first.annotations)
.toContain(new AnnotationModel()
..name = '_templates.hostViewFactory_FooComponent'
..name = 'hostViewFactory_FooComponent'
..isConstObject = true);
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toContain("import 'bar.dart'")
..toContain("import 'bar.template.dart'");
});
@ -260,7 +247,7 @@ void allTests() {
final firstOutputs = await process(fooAssetId);
final secondOutputs = await process(fooAssetId);
expect(firstOutputs.ngDeps).toEqual(secondOutputs.ngDeps);
expect(firstOutputs.templatesCode).toEqual(secondOutputs.templatesCode);
expect(_generatedCode(firstOutputs)).toEqual(_generatedCode(secondOutputs));
});
it('should generate getters for Component#outputs.', () async {
@ -370,7 +357,7 @@ void allTests() {
platformDirectives: ['package:a/bar.dart#PLATFORM']);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toBeNotNull()
..toContain(barComponentMeta.template.template);
});
@ -389,7 +376,7 @@ void allTests() {
platformDirectives: ['package:a/bar.dart#PLATFORM']);
final ngDeps = outputs.ngDeps;
expect(ngDeps).toBeNotNull();
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toBeNotNull()
..toContain(barComponentMeta.template.template);
});
@ -440,7 +427,7 @@ void allTests() {
final outputs = await process(fooAssetId);
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toContain("import 'bar.dart'")
..toContain(barPipeMeta.name);
});
@ -455,12 +442,19 @@ void allTests() {
final outputs = await process(fooAssetId,
platformPipes: ['package:a/bar.dart#PLATFORM']);
expect(outputs.templatesCode)
expect(_generatedCode(outputs))
..toContain("import 'bar.dart'")
..toContain(barPipeMeta.name);
});
}
String _generatedCode(Outputs outputs) {
final StringBuffer buf = new StringBuffer();
final writer = new NgDepsWriter(buf);
writeTemplateFile(writer, outputs.ngDeps, outputs.templatesSource);
return buf.toString();
}
void _formatThenExpectEquals(String actual, String expected) {
expect(formatter.format(actual)).toEqual(formatter.format(expected));
}