| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 @TestOn('vm') |
| 4 library web_components.test.build.transformer_test; | 5 library web_components.test.build.transformer_test; |
| 5 | 6 |
| 6 import 'package:code_transformers/tests.dart'; | 7 import 'package:transformer_test/utils.dart'; |
| 7 import 'package:web_components/transformer.dart'; | 8 import 'package:web_components/transformer.dart'; |
| 8 import 'package:unittest/compact_vm_config.dart'; | 9 import 'package:test/test.dart'; |
| 9 import 'common.dart'; | 10 import 'common.dart'; |
| 10 | 11 |
| 11 var transformer = new WebComponentsTransformerGroup( | 12 var transformer = new WebComponentsTransformerGroup( |
| 12 new TransformOptions(['web/index.html', 'test/index.html'], false)); | 13 new TransformOptions(['web/index.html', 'test/index.html'], false)); |
| 13 var phases = [[transformer]]; | 14 var phases = [ |
| 15 [transformer] |
| 16 ]; |
| 14 | 17 |
| 15 main() { | 18 main() { |
| 16 useCompactVMConfiguration(); | 19 testPhases( |
| 17 | 20 'full app', |
| 18 testPhases('full app', phases, { | 21 phases, |
| 19 'a|web/index.html': ''' | 22 { |
| 23 'a|web/index.html': ''' |
| 20 <!DOCTYPE html> | 24 <!DOCTYPE html> |
| 21 <html> | 25 <html> |
| 22 <head> | 26 <head> |
| 23 <link rel="import" href="packages/b/foo.html"> | 27 <link rel="import" href="packages/b/foo.html"> |
| 24 </head> | 28 </head> |
| 25 <body> | 29 <body> |
| 26 <script type="application/dart" src="index.dart"></script> | 30 <script type="application/dart" src="index.dart"></script> |
| 27 </body> | 31 </body> |
| 28 </html> | 32 </html> |
| 29 ''', | 33 ''', |
| 30 'a|web/index.dart': ''' | 34 'a|web/index.dart': ''' |
| 31 library a; | 35 library a; |
| 32 | 36 |
| 33 import 'package:initialize/initialize.dart'; | 37 import 'package:initialize/initialize.dart'; |
| 34 | 38 |
| 35 @initMethod | 39 @initMethod |
| 36 startup() {} | 40 startup() {} |
| 37 ''', | 41 ''', |
| 38 'b|lib/foo.html': ''' | 42 'b|lib/foo.html': ''' |
| 39 <link rel="import" href="bar.html"> | 43 <link rel="import" href="bar.html"> |
| 40 <script type="application/dart" src="foo.dart"></script> | 44 <script type="application/dart" src="foo.dart"></script> |
| 41 <div>foo</div> | 45 <div>foo</div> |
| 42 ''', | 46 ''', |
| 43 'b|lib/foo.dart': ''' | 47 'b|lib/foo.dart': ''' |
| 44 library b.foo; | 48 library b.foo; |
| 45 ''', | 49 ''', |
| 46 'b|lib/bar.html': ''' | 50 'b|lib/bar.html': ''' |
| 47 <script type="application/dart"> | 51 <script type="application/dart"> |
| 48 // Must use package:urls inside inline script tags, | 52 // Must use package:urls inside inline script tags, |
| 49 @HtmlImport('package:b/bar_nodart.html') | 53 @HtmlImport('package:b/bar_nodart.html') |
| 50 library b.bar; | 54 library b.bar; |
| 51 | 55 |
| 52 import 'package:web_components/html_import_annotation.dart'; | 56 import 'package:web_components/html_import_annotation.dart'; |
| 53 | 57 |
| 54 import 'package:initialize/initialize.dart'; | 58 import 'package:initialize/initialize.dart'; |
| 55 | 59 |
| 56 @initMethod | 60 @initMethod |
| 57 bar() {} | 61 bar() {} |
| 58 </script> | 62 </script> |
| 59 <div>bar</div> | 63 <div>bar</div> |
| 60 ''', | 64 ''', |
| 61 'b|lib/bar_nodart.html': ''' | 65 'b|lib/bar_nodart.html': ''' |
| 62 <div>bar no_dart!</div> | 66 <div>bar no_dart!</div> |
| 63 ''', | 67 ''', |
| 64 'initialize|lib/initialize.dart': mockInitialize, | 68 'initialize|lib/initialize.dart': mockInitialize, |
| 65 'web_components|lib/html_import_annotation.dart': mockHtmlImportAnnotation, | 69 'web_components|lib/html_import_annotation.dart': |
| 66 }, { | 70 mockHtmlImportAnnotation, |
| 67 'a|web/index.html': ''' | 71 }, |
| 72 { |
| 73 'a|web/index.html': ''' |
| 68 <!DOCTYPE html> | 74 <!DOCTYPE html> |
| 69 <html> | 75 <html> |
| 70 <head></head> | 76 <head></head> |
| 71 <body> | 77 <body> |
| 72 <div hidden=""> | 78 <div hidden=""> |
| 73 <div>bar</div> | 79 <div>bar</div> |
| 74 <div>foo</div> | 80 <div>foo</div> |
| 75 <div>bar no_dart!</div> | 81 <div>bar no_dart!</div> |
| 76 </div> | 82 </div> |
| 77 <script type="application/dart" src="index.bootstrap.initialize.dart
"> | 83 <script type="application/dart" src="index.bootstrap.initialize.dart
"> |
| 78 </script> | 84 </script> |
| 79 </body> | 85 </body> |
| 80 </html> | 86 </html> |
| 81 ''', | 87 ''', |
| 82 'a|web/index.bootstrap.initialize.dart': ''' | 88 'a|web/index.bootstrap.initialize.dart': ''' |
| 83 import 'package:initialize/src/static_loader.dart'; | 89 import 'package:initialize/src/static_loader.dart'; |
| 84 import 'package:initialize/initialize.dart'; | 90 import 'package:initialize/initialize.dart'; |
| 85 import 'index.bootstrap.dart' as i0; | 91 import 'index.bootstrap.dart' as i0; |
| 86 import 'index.html.0.dart' as i1; | 92 import 'index.html.0.dart' as i1; |
| 87 import 'package:web_components/html_import_annotation.dart' as i2; | 93 import 'package:web_components/html_import_annotation.dart' as i2; |
| 88 import 'package:initialize/initialize.dart' as i3; | 94 import 'package:initialize/initialize.dart' as i3; |
| 89 import 'index.dart' as i4; | 95 import 'index.dart' as i4; |
| 90 | 96 |
| 91 main() { | 97 main() { |
| 92 initializers.addAll([ | 98 initializers.addAll([ |
| 93 new InitEntry(i3.initMethod, i1.bar), | 99 new InitEntry(i3.initMethod, i1.bar), |
| 94 new InitEntry(i3.initMethod, i4.startup), | 100 new InitEntry(i3.initMethod, i4.startup), |
| 95 ]); | 101 ]); |
| 96 return i0.main(); | 102 return i0.main(); |
| 97 } | 103 } |
| 98 ''', | 104 ''', |
| 99 'a|web/index.bootstrap.dart': ''' | 105 'a|web/index.bootstrap.dart': ''' |
| 100 library a.web.index_bootstrap_dart; | 106 library a.web.index_bootstrap_dart; |
| 101 | 107 |
| 102 import 'index.html.0.dart' as i0; | 108 import 'index.html.0.dart' as i0; |
| 103 import 'package:b/foo.dart' as i1; | 109 import 'package:b/foo.dart' as i1; |
| 104 import 'index.dart' as i2; | 110 import 'index.dart' as i2; |
| 105 | 111 |
| 106 main() => i2.main(); | 112 main() => i2.main(); |
| 107 ''', | 113 ''', |
| 108 'a|web/index.html.0.dart': ''' | 114 'a|web/index.html.0.dart': ''' |
| 109 // Must use package:urls inside inline script tags, | 115 // Must use package:urls inside inline script tags, |
| 110 @HtmlImport('package:b/bar_nodart.html') | 116 @HtmlImport('package:b/bar_nodart.html') |
| 111 library b.bar; | 117 library b.bar; |
| 112 | 118 |
| 113 import 'package:web_components/html_import_annotation.dart'; | 119 import 'package:web_components/html_import_annotation.dart'; |
| 114 | 120 |
| 115 import 'package:initialize/initialize.dart'; | 121 import 'package:initialize/initialize.dart'; |
| 116 | 122 |
| 117 @initMethod | 123 @initMethod |
| 118 bar() {} | 124 bar() {} |
| 119 ''', | 125 ''', |
| 120 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 126 }, |
| 127 messages: [], |
| 128 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 121 | 129 |
| 122 testPhases('imports go above the dart script', phases, { | 130 testPhases( |
| 123 'b|web/index.html': ''' | 131 'imports go above the dart script', |
| 132 phases, |
| 133 { |
| 134 'b|web/index.html': ''' |
| 124 <!DOCTYPE html> | 135 <!DOCTYPE html> |
| 125 <html> | 136 <html> |
| 126 <head> | 137 <head> |
| 127 <script>var x;</script> | 138 <script>var x;</script> |
| 128 <script type="application/dart" src="index.dart"></script> | 139 <script type="application/dart" src="index.dart"></script> |
| 129 <script>var y;</script> | 140 <script>var y;</script> |
| 130 </head> | 141 </head> |
| 131 <body> | 142 <body> |
| 132 </body> | 143 </body> |
| 133 </html> | 144 </html> |
| 134 ''', | 145 ''', |
| 135 'b|web/index.dart': ''' | 146 'b|web/index.dart': ''' |
| 136 @HtmlImport('package:b/b.html') | 147 @HtmlImport('package:b/b.html') |
| 137 library b; | 148 library b; |
| 138 | 149 |
| 139 import 'package:web_components/html_import_annotation.dart'; | 150 import 'package:web_components/html_import_annotation.dart'; |
| 140 import 'package:c/c.dart'; | 151 import 'package:c/c.dart'; |
| 141 ''', | 152 ''', |
| 142 'b|lib/b.html': ''' | 153 'b|lib/b.html': ''' |
| 143 <div>b</div> | 154 <div>b</div> |
| 144 ''', | 155 ''', |
| 145 'c|lib/c.dart': ''' | 156 'c|lib/c.dart': ''' |
| 146 @HtmlImport('c.html') | 157 @HtmlImport('c.html') |
| 147 library c; | 158 library c; |
| 148 | 159 |
| 149 import 'package:web_components/html_import_annotation.dart'; | 160 import 'package:web_components/html_import_annotation.dart'; |
| 150 ''', | 161 ''', |
| 151 'c|lib/c.html': ''' | 162 'c|lib/c.html': ''' |
| 152 <div>c</div> | 163 <div>c</div> |
| 153 ''', | 164 ''', |
| 154 'initialize|lib/initialize.dart': mockInitialize, | 165 'initialize|lib/initialize.dart': mockInitialize, |
| 155 'web_components|lib/html_import_annotation.dart': mockHtmlImportAnnotation, | 166 'web_components|lib/html_import_annotation.dart': |
| 156 }, { | 167 mockHtmlImportAnnotation, |
| 157 'b|web/index.html': ''' | 168 }, |
| 169 { |
| 170 'b|web/index.html': ''' |
| 158 <!DOCTYPE html> | 171 <!DOCTYPE html> |
| 159 <html> | 172 <html> |
| 160 <head> | 173 <head> |
| 161 <script>var x;</script> | 174 <script>var x;</script> |
| 162 </head> | 175 </head> |
| 163 <body> | 176 <body> |
| 164 <div hidden=""> | 177 <div hidden=""> |
| 165 <div>c</div> | 178 <div>c</div> |
| 166 <div>b</div> | 179 <div>b</div> |
| 167 <script type="application/dart" src="index.bootstrap.initialize.da
rt"> | 180 <script type="application/dart" src="index.bootstrap.initialize.da
rt"> |
| 168 </script> | 181 </script> |
| 169 <script>var y;</script> | 182 <script>var y;</script> |
| 170 </div> | 183 </div> |
| 171 </body> | 184 </body> |
| 172 </html> | 185 </html> |
| 173 ''', | 186 ''', |
| 174 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 187 }, |
| 188 messages: [], |
| 189 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 175 | 190 |
| 176 testPhases('test compatibility', phases, { | 191 testPhases( |
| 177 'a|test/index.html': ''' | 192 'test compatibility', |
| 193 phases, |
| 194 { |
| 195 'a|test/index.html': ''' |
| 178 <!DOCTYPE html> | 196 <!DOCTYPE html> |
| 179 <html> | 197 <html> |
| 180 <head> | 198 <head> |
| 181 <link rel="x-dart-test" href="index.dart"> | 199 <link rel="x-dart-test" href="index.dart"> |
| 182 <script src="packages/test/dart.js"></script> | 200 <script src="packages/test/dart.js"></script> |
| 183 </head> | 201 </head> |
| 184 <body></body> | 202 <body></body> |
| 185 </html> | 203 </html> |
| 186 ''', | 204 ''', |
| 187 'a|test/index.dart': ''' | 205 'a|test/index.dart': ''' |
| 188 library a; | 206 library a; |
| 189 | 207 |
| 190 main() {} | 208 main() {} |
| 191 ''', | 209 ''', |
| 192 'initialize|lib/initialize.dart': mockInitialize, | 210 'initialize|lib/initialize.dart': mockInitialize, |
| 193 'web_components|lib/html_import_annotation.dart': mockHtmlImportAnnotation, | 211 'web_components|lib/html_import_annotation.dart': |
| 194 }, { | 212 mockHtmlImportAnnotation, |
| 195 'a|test/index.html': ''' | 213 }, |
| 214 { |
| 215 'a|test/index.html': ''' |
| 196 <!DOCTYPE html> | 216 <!DOCTYPE html> |
| 197 <html> | 217 <html> |
| 198 <head> | 218 <head> |
| 199 <link rel="x-dart-test" href="index.bootstrap.initialize.dart"> | 219 <link rel="x-dart-test" href="index.bootstrap.initialize.dart"> |
| 200 <script src="packages/test/dart.js"></script> | 220 <script src="packages/test/dart.js"></script> |
| 201 </head> | 221 </head> |
| 202 <body></body> | 222 <body></body> |
| 203 </html> | 223 </html> |
| 204 ''', | 224 ''', |
| 205 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 225 }, |
| 226 messages: [], |
| 227 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 206 } | 228 } |
| OLD | NEW |