| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  | library angular2.test.transform.integration; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 15:54:12 -07:00
										 |  |  | import 'package:angular2/src/dom/html_adapter.dart'; | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  | import 'package:angular2/transformer.dart'; | 
					
						
							|  |  |  | import 'package:code_transformers/tests.dart'; | 
					
						
							|  |  |  | import 'package:dart_style/dart_style.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import '../common/read_file.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-19 15:47:10 -07:00
										 |  |  | main() { | 
					
						
							|  |  |  |   allTests(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  | var formatter = new DartFormatter(); | 
					
						
							|  |  |  | var transform = new AngularTransformerGroup(new TransformerOptions( | 
					
						
							| 
									
										
										
										
											2015-04-17 11:12:35 -07:00
										 |  |  |     ['web/index.dart'], reflectionEntryPoints: ['web/index.dart'])); | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class IntegrationTestConfig { | 
					
						
							|  |  |  |   final String name; | 
					
						
							|  |  |  |   final Map<String, String> assetPathToInputPath; | 
					
						
							|  |  |  |   final Map<String, String> assetPathToExpectedOutputPath; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   IntegrationTestConfig(this.name, | 
					
						
							|  |  |  |       {Map<String, String> inputs, Map<String, String> outputs}) | 
					
						
							|  |  |  |       : this.assetPathToInputPath = inputs, | 
					
						
							|  |  |  |         this.assetPathToExpectedOutputPath = outputs; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void allTests() { | 
					
						
							| 
									
										
										
										
											2015-03-13 13:55:49 -07:00
										 |  |  |   Html5LibDomAdapter.makeCurrent(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |   /* | 
					
						
							|  |  |  |    * Each test has its own directory for inputs & an `expected` directory for | 
					
						
							|  |  |  |    * expected outputs. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * In addition to these declared inputs, we inject a set of common inputs for | 
					
						
							|  |  |  |    * every test. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   var commonInputs = { | 
					
						
							| 
									
										
										
										
											2015-04-28 18:17:00 -07:00
										 |  |  |     'angular2|lib/src/core/annotations_impl/annotations.dart': | 
					
						
							|  |  |  |         '../../../lib/src/core/annotations_impl/annotations.dart', | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |     'angular2|lib/src/core/application.dart': '../common/application.dart', | 
					
						
							|  |  |  |     'angular2|lib/src/reflection/reflection_capabilities.dart': | 
					
						
							| 
									
										
										
										
											2015-03-19 15:47:10 -07:00
										 |  |  |         '../common/reflection_capabilities.dart', | 
					
						
							|  |  |  |     'angular2|lib/di.dart': '../../../lib/di.dart', | 
					
						
							| 
									
										
										
										
											2015-07-08 12:04:24 -07:00
										 |  |  |     'angular2|lib/src/di/decorators.dart': | 
					
						
							|  |  |  |         '../../../lib/src/di/decorators.dart', | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var tests = [ | 
					
						
							|  |  |  |     new IntegrationTestConfig( | 
					
						
							|  |  |  |         'should generate proper code for a Component defining only a selector.', | 
					
						
							|  |  |  |         inputs: { | 
					
						
							|  |  |  |       'a|web/index.dart': 'simple_annotation_files/index.dart', | 
					
						
							|  |  |  |       'a|web/bar.dart': 'simple_annotation_files/bar.dart' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |         outputs: { | 
					
						
							| 
									
										
										
										
											2015-03-16 13:32:29 -07:00
										 |  |  |       'a|web/bar.ng_deps.dart': | 
					
						
							|  |  |  |           'simple_annotation_files/expected/bar.ng_deps.dart', | 
					
						
							| 
									
										
										
										
											2015-05-05 10:31:21 -07:00
										 |  |  |       'a|web/bar.ng_meta.json': | 
					
						
							|  |  |  |           'simple_annotation_files/expected/bar.ng_meta.json', | 
					
						
							| 
									
										
										
										
											2015-03-16 13:32:29 -07:00
										 |  |  |       'a|web/index.ng_deps.dart': | 
					
						
							|  |  |  |           'simple_annotation_files/expected/index.ng_deps.dart' | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     new IntegrationTestConfig( | 
					
						
							| 
									
										
										
										
											2015-05-01 13:57:44 -07:00
										 |  |  |         'should generate proper code for a Component with multiple deps.', | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |         inputs: { | 
					
						
							|  |  |  |       'a|web/index.dart': 'two_deps_files/index.dart', | 
					
						
							|  |  |  |       'a|web/foo.dart': 'two_deps_files/foo.dart', | 
					
						
							|  |  |  |       'a|web/bar.dart': 'two_deps_files/bar.dart' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |         outputs: { | 
					
						
							| 
									
										
										
										
											2015-03-16 13:32:29 -07:00
										 |  |  |       'a|web/bar.ng_deps.dart': 'two_deps_files/expected/bar.ng_deps.dart' | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     new IntegrationTestConfig( | 
					
						
							|  |  |  |         'should generate proper code for a Component declaring a ' | 
					
						
							|  |  |  |         'componentService defined in another file.', | 
					
						
							|  |  |  |         inputs: { | 
					
						
							|  |  |  |       'a|web/index.dart': 'list_of_types_files/index.dart', | 
					
						
							|  |  |  |       'a|web/foo.dart': 'list_of_types_files/foo.dart', | 
					
						
							|  |  |  |       'a|web/bar.dart': 'list_of_types_files/bar.dart' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |         outputs: { | 
					
						
							| 
									
										
										
										
											2015-03-16 13:32:29 -07:00
										 |  |  |       'a|web/bar.ng_deps.dart': 'list_of_types_files/expected/bar.ng_deps.dart' | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     new IntegrationTestConfig( | 
					
						
							|  |  |  |         'should generate a factory for a class with no declared ctor.', | 
					
						
							|  |  |  |         inputs: { | 
					
						
							|  |  |  |       'a|web/index.dart': 'synthetic_ctor_files/index.dart', | 
					
						
							|  |  |  |       'a|web/bar.dart': 'synthetic_ctor_files/bar.dart' | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |         outputs: { | 
					
						
							| 
									
										
										
										
											2015-03-16 13:32:29 -07:00
										 |  |  |       'a|web/bar.ng_deps.dart': 'synthetic_ctor_files/expected/bar.ng_deps.dart' | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     new IntegrationTestConfig('should preserve multiple annotations.', | 
					
						
							|  |  |  |         inputs: { | 
					
						
							|  |  |  |       'a|web/index.dart': 'two_annotations_files/index.dart', | 
					
						
							|  |  |  |       'a|web/bar.dart': 'two_annotations_files/bar.dart', | 
					
						
							| 
									
										
										
										
											2015-04-28 18:17:00 -07:00
										 |  |  |       'angular2|lib/src/core/annotations_impl/view.dart': | 
					
						
							|  |  |  |           '../../../lib/src/core/annotations_impl/view.dart' | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |     }, | 
					
						
							|  |  |  |         outputs: { | 
					
						
							| 
									
										
										
										
											2015-03-16 13:32:29 -07:00
										 |  |  |       'a|web/bar.ng_deps.dart': | 
					
						
							|  |  |  |           'two_annotations_files/expected/bar.ng_deps.dart' | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |     }) | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var cache = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (var config in tests) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Read in input & output files.
 | 
					
						
							|  |  |  |     config.assetPathToInputPath | 
					
						
							|  |  |  |       ..addAll(commonInputs) | 
					
						
							|  |  |  |       ..forEach((key, value) { | 
					
						
							|  |  |  |         config.assetPathToInputPath[key] = | 
					
						
							|  |  |  |             cache.putIfAbsent(value, () => _readFile(value)); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     config.assetPathToExpectedOutputPath.forEach((key, value) { | 
					
						
							|  |  |  |       config.assetPathToExpectedOutputPath[key] = cache.putIfAbsent(value, () { | 
					
						
							|  |  |  |         var code = _readFile(value); | 
					
						
							|  |  |  |         return value.endsWith('dart') ? formatter.format(code) : code; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-03-19 09:16:01 -07:00
										 |  |  |     testPhases(config.name, [[transform]], config.assetPathToInputPath, | 
					
						
							| 
									
										
										
										
											2015-07-09 13:59:36 -07:00
										 |  |  |         config.assetPathToExpectedOutputPath, [], | 
					
						
							|  |  |  |         StringFormatter.noNewlinesOrSurroundingWhitespace); | 
					
						
							| 
									
										
										
										
											2015-03-06 11:10:14 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Smooths over differences in CWD between IDEs and running tests in Travis.
 | 
					
						
							|  |  |  | String _readFile(String path) => readFile('integration/$path'); |