| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 4 |
| 5 library polymer.test.build.all_phases_test; | 5 library polymer.test.build.all_phases_test; |
| 6 | 6 |
| 7 import 'package:polymer/src/build/common.dart'; | 7 import 'package:polymer/src/build/common.dart'; |
| 8 import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER; | 8 import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER; |
| 9 import 'package:polymer/transformer.dart'; | 9 import 'package:polymer/transformer.dart'; |
| 10 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:unittest/compact_vm_config.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 'a|web/test2.dart': _sampleObservableOutput('B', 'bar'), | 29 'a|web/test2.dart': _sampleObservableOutput('B', 'bar'), |
| 30 }); | 30 }); |
| 31 | 31 |
| 32 testPhases('single script', phases, { | 32 testPhases('single script', phases, { |
| 33 'a|web/test.html': | 33 'a|web/test.html': |
| 34 '<!DOCTYPE html><html><head>' | 34 '<!DOCTYPE html><html><head>' |
| 35 '<script type="application/dart" src="a.dart"></script>', | 35 '<script type="application/dart" src="a.dart"></script>', |
| 36 'a|web/test.dart': _sampleObservable('A', 'foo'), | 36 'a|web/test.dart': _sampleObservable('A', 'foo'), |
| 37 }, { | 37 }, { |
| 38 'a|web/test.html': | 38 'a|web/test.html': |
| 39 '<!DOCTYPE html><html><head></head><body>' | 39 '<!DOCTYPE html><html><head>' |
| 40 '$SHADOW_DOM_TAG' | 40 '$SHADOW_DOM_TAG' |
| 41 '$CUSTOM_ELEMENT_TAG' | 41 '$CUSTOM_ELEMENT_TAG' |
| 42 '$INTEROP_TAG' | 42 '$INTEROP_TAG' |
| 43 '<script src="test.html_bootstrap.dart.js"></script>' | 43 '<script src="test.html_bootstrap.dart.js"></script>' |
| 44 '</body></html>', | 44 '</head><body></body></html>', |
| 45 | 45 |
| 46 'a|web/test.html_bootstrap.dart': | 46 'a|web/test.html_bootstrap.dart': |
| 47 '''$MAIN_HEADER | 47 '''$MAIN_HEADER |
| 48 import 'a.dart' as i0; | 48 import 'a.dart' as i0; |
| 49 | 49 |
| 50 void main() { | 50 void main() { |
| 51 initPolymer([ | 51 configureForDeployment([ |
| 52 'a.dart', | 52 'a.dart', |
| 53 ]); | 53 ]); |
| 54 i0.main(); |
| 54 } | 55 } |
| 55 '''.replaceAll('\n ', '\n'), | 56 '''.replaceAll('\n ', '\n'), |
| 56 'a|web/test.dart': _sampleObservableOutput('A', 'foo'), | 57 'a|web/test.dart': _sampleObservableOutput('A', 'foo'), |
| 57 }); | 58 }); |
| 58 | 59 |
| 59 testPhases('single inline script', phases, { | 60 testPhases('single inline script', phases, { |
| 60 'a|web/test.html': | 61 'a|web/test.html': |
| 61 '<!DOCTYPE html><html><head>' | 62 '<!DOCTYPE html><html><head>' |
| 62 '<script type="application/dart">' | 63 '<script type="application/dart">' |
| 63 '${_sampleObservable("B", "bar")}</script>', | 64 '${_sampleObservable("B", "bar")}</script>', |
| 64 }, { | 65 }, { |
| 65 'a|web/test.html': | 66 'a|web/test.html': |
| 66 '<!DOCTYPE html><html><head></head><body>' | 67 '<!DOCTYPE html><html><head>' |
| 67 '$SHADOW_DOM_TAG' | 68 '$SHADOW_DOM_TAG' |
| 68 '$CUSTOM_ELEMENT_TAG' | 69 '$CUSTOM_ELEMENT_TAG' |
| 69 '$INTEROP_TAG' | 70 '$INTEROP_TAG' |
| 70 '<script src="test.html_bootstrap.dart.js"></script>' | 71 '<script src="test.html_bootstrap.dart.js"></script>' |
| 71 '</body></html>', | 72 '</head><body></body></html>', |
| 72 | 73 |
| 73 'a|web/test.html_bootstrap.dart': | 74 'a|web/test.html_bootstrap.dart': |
| 74 '''$MAIN_HEADER | 75 '''$MAIN_HEADER |
| 75 import 'test.html.0.dart' as i0; | 76 import 'test.html.0.dart' as i0; |
| 76 | 77 |
| 77 void main() { | 78 void main() { |
| 78 initPolymer([ | 79 configureForDeployment([ |
| 79 'test.html.0.dart', | 80 'test.html.0.dart', |
| 80 ]); | 81 ]); |
| 82 i0.main(); |
| 81 } | 83 } |
| 82 '''.replaceAll('\n ', '\n'), | 84 '''.replaceAll('\n ', '\n'), |
| 83 'a|web/test.html.0.dart': _sampleObservableOutput("B", "bar"), | 85 'a|web/test.html.0.dart': _sampleObservableOutput("B", "bar"), |
| 84 }); | 86 }); |
| 85 | 87 |
| 86 testPhases('several scripts', phases, { | 88 testPhases('several scripts', phases, { |
| 87 'a|web/test.html': | 89 'a|web/test.html': |
| 88 '<!DOCTYPE html><html><head>' | 90 '<!DOCTYPE html><html><head>' |
| 89 '<script type="application/dart" src="a.dart"></script>' | 91 '<script type="application/dart" src="a.dart"></script>' |
| 92 // TODO(sigmund): provide a way to see logging warnings and errors. |
| 93 // For example, these extra tags produce warnings and are then removed |
| 94 // by the transformers. The test below checks that the output looks |
| 95 // correct, but we should also validate the messages logged. |
| 90 '<script type="application/dart">' | 96 '<script type="application/dart">' |
| 91 '${_sampleObservable("B", "bar")}</script>' | 97 '${_sampleObservable("B", "bar")}</script>' |
| 92 '</head><body><div>' | 98 '</head><body><div>' |
| 93 '<script type="application/dart">' | 99 '<script type="application/dart">' |
| 94 '${_sampleObservable("C", "car")}</script>' | 100 '${_sampleObservable("C", "car")}</script>' |
| 95 '</div>' | 101 '</div>' |
| 96 '<script type="application/dart" src="d.dart"></script>', | 102 '<script type="application/dart" src="d.dart"></script>', |
| 97 'a|web/a.dart': _sampleObservable('A', 'foo'), | 103 'a|web/a.dart': _sampleObservable('A', 'foo'), |
| 98 }, { | 104 }, { |
| 99 'a|web/test.html': | 105 'a|web/test.html': |
| 100 '<!DOCTYPE html><html><head></head><body>' | 106 '<!DOCTYPE html><html><head>' |
| 101 '$SHADOW_DOM_TAG' | 107 '$SHADOW_DOM_TAG' |
| 102 '$CUSTOM_ELEMENT_TAG' | 108 '$CUSTOM_ELEMENT_TAG' |
| 103 '$INTEROP_TAG' | 109 '$INTEROP_TAG' |
| 110 '<script src="test.html_bootstrap.dart.js"></script>' |
| 111 '</head><body>' |
| 104 '<div></div>' | 112 '<div></div>' |
| 105 '<script src="test.html_bootstrap.dart.js"></script>' | |
| 106 '</body></html>', | 113 '</body></html>', |
| 107 | 114 |
| 108 'a|web/test.html_bootstrap.dart': | 115 'a|web/test.html_bootstrap.dart': |
| 109 '''$MAIN_HEADER | 116 '''$MAIN_HEADER |
| 110 import 'a.dart' as i0; | 117 import 'a.dart' as i0; |
| 111 import 'test.html.0.dart' as i1; | |
| 112 import 'test.html.1.dart' as i2; | |
| 113 import 'd.dart' as i3; | |
| 114 | 118 |
| 115 void main() { | 119 void main() { |
| 116 initPolymer([ | 120 configureForDeployment([ |
| 117 'a.dart', | 121 'a.dart', |
| 118 'test.html.0.dart', | |
| 119 'test.html.1.dart', | |
| 120 'd.dart', | |
| 121 ]); | 122 ]); |
| 123 i0.main(); |
| 122 } | 124 } |
| 123 '''.replaceAll('\n ', '\n'), | 125 '''.replaceAll('\n ', '\n'), |
| 124 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), | 126 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), |
| 125 'a|web/test.html.0.dart': _sampleObservableOutput("B", "bar"), | 127 'a|web/test.html.0.dart': _sampleObservableOutput("B", "bar"), |
| 126 'a|web/test.html.1.dart': _sampleObservableOutput("C", "car"), | 128 'a|web/test.html.1.dart': _sampleObservableOutput("C", "car"), |
| 127 }); | 129 }); |
| 128 | 130 |
| 129 testPhases('with imports', phases, { | 131 testPhases('with imports', phases, { |
| 130 'a|web/index.html': | 132 'a|web/index.html': |
| 131 '<!DOCTYPE html><html><head>' | 133 '<!DOCTYPE html><html><head>' |
| 132 '<link rel="import" href="test2.html">' | 134 '<link rel="import" href="test2.html">' |
| 133 '</head><body>' | 135 '</head><body>' |
| 134 '<script type="application/dart" src="b.dart"></script>' | 136 '<script type="application/dart" src="b.dart"></script>', |
| 135 '<script type="application/dart">' | |
| 136 '${_sampleObservable("C", "car")}</script>', | |
| 137 'a|web/b.dart': _sampleObservable('B', 'bar'), | 137 'a|web/b.dart': _sampleObservable('B', 'bar'), |
| 138 'a|web/test2.html': | 138 'a|web/test2.html': |
| 139 '<!DOCTYPE html><html><head></head><body>' | 139 '<!DOCTYPE html><html><head></head><body>' |
| 140 '<polymer-element>1' | 140 '<polymer-element>1' |
| 141 '<script type="application/dart">' | 141 '<script type="application/dart">' |
| 142 '${_sampleObservable("A", "foo")}</script>' | 142 '${_sampleObservable("A", "foo")}</script>' |
| 143 '</polymer-element></html>', | 143 '</polymer-element></html>', |
| 144 }, { | 144 }, { |
| 145 'a|web/index.html': | 145 'a|web/index.html': |
| 146 '<!DOCTYPE html><html><head></head><body>' | 146 '<!DOCTYPE html><html><head>' |
| 147 '$SHADOW_DOM_TAG' | 147 '$SHADOW_DOM_TAG' |
| 148 '$CUSTOM_ELEMENT_TAG' | 148 '$CUSTOM_ELEMENT_TAG' |
| 149 '$INTEROP_TAG' | 149 '$INTEROP_TAG' |
| 150 '<polymer-element>1</polymer-element>' | 150 '</head><body><polymer-element>1</polymer-element>' |
| 151 '<script src="index.html_bootstrap.dart.js"></script>' | 151 '<script src="index.html_bootstrap.dart.js"></script>' |
| 152 '</body></html>', | 152 '</body></html>', |
| 153 'a|web/index.html_bootstrap.dart': | 153 'a|web/index.html_bootstrap.dart': |
| 154 '''$MAIN_HEADER | 154 '''$MAIN_HEADER |
| 155 import 'test2.html.0.dart' as i0; | 155 import 'test2.html.0.dart' as i0; |
| 156 import 'b.dart' as i1; | 156 import 'b.dart' as i1; |
| 157 import 'index.html.0.dart' as i2; | |
| 158 | 157 |
| 159 void main() { | 158 void main() { |
| 160 initPolymer([ | 159 configureForDeployment([ |
| 161 'test2.html.0.dart', | 160 'test2.html.0.dart', |
| 162 'b.dart', | 161 'b.dart', |
| 163 'index.html.0.dart', | |
| 164 ]); | 162 ]); |
| 163 i1.main(); |
| 165 } | 164 } |
| 166 '''.replaceAll('\n ', '\n'), | 165 '''.replaceAll('\n ', '\n'), |
| 167 'a|web/test2.html.0.dart': _sampleObservableOutput("A", "foo"), | 166 'a|web/test2.html.0.dart': _sampleObservableOutput("A", "foo"), |
| 168 'a|web/b.dart': _sampleObservableOutput('B', 'bar'), | 167 'a|web/b.dart': _sampleObservableOutput('B', 'bar'), |
| 169 'a|web/index.html.0.dart': _sampleObservableOutput("C", "car"), | |
| 170 }); | 168 }); |
| 171 } | 169 } |
| 172 | 170 |
| 173 String _sampleObservable(String className, String fieldName) => ''' | 171 String _sampleObservable(String className, String fieldName) => ''' |
| 174 library ${className}_$fieldName; | 172 library ${className}_$fieldName; |
| 175 import 'package:observe/observe.dart'; | 173 import 'package:observe/observe.dart'; |
| 176 | 174 |
| 177 class $className extends Observable { | 175 class $className extends Observable { |
| 178 @observable int $fieldName; | 176 @observable int $fieldName; |
| 179 $className(this.$fieldName); | 177 $className(this.$fieldName); |
| 180 } | 178 } |
| 181 '''; | 179 '''; |
| 182 | 180 |
| 183 String _sampleObservableOutput(String className, String field) => | 181 String _sampleObservableOutput(String className, String field) => |
| 184 "library ${className}_$field;\n" | 182 "library ${className}_$field;\n" |
| 185 "import 'package:observe/observe.dart';\n\n" | 183 "import 'package:observe/observe.dart';\n\n" |
| 186 "class $className extends ChangeNotifier {\n" | 184 "class $className extends ChangeNotifier {\n" |
| 187 " @reflectable @observable int get $field => __\$$field; " | 185 " @reflectable @observable int get $field => __\$$field; " |
| 188 "int __\$$field; " | 186 "int __\$$field; " |
| 189 "@reflectable set $field(int value) { " | 187 "@reflectable set $field(int value) { " |
| 190 "__\$$field = notifyPropertyChange(#$field, __\$$field, value); " | 188 "__\$$field = notifyPropertyChange(#$field, __\$$field, value); " |
| 191 "}\n" | 189 "}\n" |
| 192 " $className($field) : __\$$field = $field;\n" | 190 " $className($field) : __\$$field = $field;\n" |
| 193 "}\n"; | 191 "}\n"; |
| OLD | NEW |