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