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:code_transformers/tests.dart' show testingDartSdkDirectory; |
7 import 'package:polymer/src/build/common.dart'; | 8 import 'package:polymer/src/build/common.dart'; |
8 import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER; | 9 import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER; |
9 import 'package:polymer/transformer.dart'; | 10 import 'package:polymer/transformer.dart'; |
| 11 import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS; |
10 import 'package:unittest/compact_vm_config.dart'; | 12 import 'package:unittest/compact_vm_config.dart'; |
11 | 13 |
12 import 'common.dart'; | 14 import 'common.dart'; |
13 | 15 |
14 void main() { | 16 void main() { |
15 useCompactVMConfiguration(); | 17 useCompactVMConfiguration(); |
16 var phases = new PolymerTransformerGroup(new TransformOptions()).phases; | 18 var phases = createDeployPhases(new TransformOptions(), |
| 19 sdkDir: testingDartSdkDirectory); |
17 | 20 |
18 testPhases('no changes', phases, { | 21 testPhases('no changes', phases, { |
19 'a|web/test.html': '<!DOCTYPE html><html></html>', | 22 'a|web/test.html': '<!DOCTYPE html><html></html>', |
20 }, {}, [ | 23 }, {}, [ |
21 'error: To run a polymer application, you need to call "initPolymer". You' | 24 'error: To run a polymer application, you need to call "initPolymer". You' |
22 ' can either include a generic script tag that does this for you:\'<' | 25 ' can either include a generic script tag that does this for you:\'<' |
23 'script type="application/dart">export "package:polymer/init.dart";' | 26 'script type="application/dart">export "package:polymer/init.dart";' |
24 '</script>\' or add your own script tag and call that function. Make sure' | 27 '</script>\' or add your own script tag and call that function. Make sure' |
25 ' the script tag is placed after all HTML imports.' | 28 ' the script tag is placed after all HTML imports.' |
26 ]); | 29 ]); |
(...skipping 15 matching lines...) Expand all Loading... |
42 'a|web/test.html': | 45 'a|web/test.html': |
43 '<!DOCTYPE html><html><head>' | 46 '<!DOCTYPE html><html><head>' |
44 '$WEB_COMPONENTS_TAG' | 47 '$WEB_COMPONENTS_TAG' |
45 '$INTEROP_TAG' | 48 '$INTEROP_TAG' |
46 '<script src="test.html_bootstrap.dart.js"></script>' | 49 '<script src="test.html_bootstrap.dart.js"></script>' |
47 '</head><body></body></html>', | 50 '</head><body></body></html>', |
48 | 51 |
49 'a|web/test.html_bootstrap.dart': | 52 'a|web/test.html_bootstrap.dart': |
50 '''$MAIN_HEADER | 53 '''$MAIN_HEADER |
51 import 'a.dart' as i0; | 54 import 'a.dart' as i0; |
| 55 ${DEFAULT_IMPORTS.join('\n')} |
52 | 56 |
53 void main() { | 57 void main() { |
| 58 useGeneratedCode(new StaticConfiguration( |
| 59 checkedMode: false)); |
54 configureForDeployment([ | 60 configureForDeployment([ |
55 ]); | 61 ]); |
56 i0.main(); | 62 i0.main(); |
57 } | 63 } |
58 '''.replaceAll('\n ', '\n'), | 64 '''.replaceAll('\n ', '\n'), |
59 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), | 65 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), |
60 }); | 66 }); |
61 | 67 |
62 testPhases('single inline script', phases, { | 68 testPhases('single inline script', phases, { |
63 'a|web/test.html': | 69 'a|web/test.html': |
64 '<!DOCTYPE html><html><head>' | 70 '<!DOCTYPE html><html><head>' |
65 '<script type="application/dart">' | 71 '<script type="application/dart">' |
66 '${_sampleObservable("B", "bar")}</script>', | 72 '${_sampleObservable("B", "bar")}</script>', |
67 }, { | 73 }, { |
68 'a|web/test.html': | 74 'a|web/test.html': |
69 '<!DOCTYPE html><html><head>' | 75 '<!DOCTYPE html><html><head>' |
70 '$WEB_COMPONENTS_TAG' | 76 '$WEB_COMPONENTS_TAG' |
71 '$INTEROP_TAG' | 77 '$INTEROP_TAG' |
72 '</head><body>' | 78 '</head><body>' |
73 '<script src="test.html_bootstrap.dart.js"></script>' | 79 '<script src="test.html_bootstrap.dart.js"></script>' |
74 '</body></html>', | 80 '</body></html>', |
75 | 81 |
76 'a|web/test.html_bootstrap.dart': | 82 'a|web/test.html_bootstrap.dart': |
77 '''$MAIN_HEADER | 83 '''$MAIN_HEADER |
78 import 'test.html.0.dart' as i0; | 84 import 'test.html.0.dart' as i0; |
| 85 ${DEFAULT_IMPORTS.join('\n')} |
79 | 86 |
80 void main() { | 87 void main() { |
| 88 useGeneratedCode(new StaticConfiguration( |
| 89 checkedMode: false)); |
81 configureForDeployment([ | 90 configureForDeployment([ |
82 ]); | 91 ]); |
83 i0.main(); | 92 i0.main(); |
84 } | 93 } |
85 '''.replaceAll('\n ', '\n'), | 94 '''.replaceAll('\n ', '\n'), |
86 'a|web/test.html.0.dart': | 95 'a|web/test.html.0.dart': |
87 _sampleObservableOutput("B", "bar"), | 96 _sampleObservableOutput("B", "bar"), |
88 }); | 97 }); |
89 | 98 |
90 const onlyOne = 'warning: Only one "application/dart" script tag per document' | 99 const onlyOne = 'warning: Only one "application/dart" script tag per document' |
(...skipping 24 matching lines...) Expand all Loading... |
115 '$WEB_COMPONENTS_TAG' | 124 '$WEB_COMPONENTS_TAG' |
116 '$INTEROP_TAG' | 125 '$INTEROP_TAG' |
117 '</head><body>' | 126 '</head><body>' |
118 '<script src="test.html_bootstrap.dart.js"></script>' | 127 '<script src="test.html_bootstrap.dart.js"></script>' |
119 '<div></div>' | 128 '<div></div>' |
120 '</body></html>', | 129 '</body></html>', |
121 | 130 |
122 'a|web/test.html_bootstrap.dart': | 131 'a|web/test.html_bootstrap.dart': |
123 '''$MAIN_HEADER | 132 '''$MAIN_HEADER |
124 import 'a.dart' as i0; | 133 import 'a.dart' as i0; |
| 134 ${DEFAULT_IMPORTS.join('\n')} |
125 | 135 |
126 void main() { | 136 void main() { |
| 137 useGeneratedCode(new StaticConfiguration( |
| 138 checkedMode: false)); |
127 configureForDeployment([ | 139 configureForDeployment([ |
128 ]); | 140 ]); |
129 i0.main(); | 141 i0.main(); |
130 } | 142 } |
131 '''.replaceAll('\n ', '\n'), | 143 '''.replaceAll('\n ', '\n'), |
132 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), | 144 'a|web/a.dart': _sampleObservableOutput('A', 'foo'), |
133 }, [ | 145 }, [ |
134 // These should not be emitted multiple times. See: | 146 // These should not be emitted multiple times. See: |
135 // https://code.google.com/p/dart/issues/detail?id=17197 | 147 // https://code.google.com/p/dart/issues/detail?id=17197 |
136 '$onlyOne (web/test.html 0 81)', | 148 '$onlyOne (web/test.html 0 81)', |
137 '$onlyOne (web/test.html 7 27)', | 149 '$onlyOne (web/test.html 8 27)', |
138 '$onlyOne (web/test.html 14 15)', | 150 '$onlyOne (web/test.html 16 15)', |
139 '$moreNotSupported (web/test.html 0 81)', | 151 '$moreNotSupported (web/test.html 0 81)', |
140 '$moreNotSupported (web/test.html 7 27)', | 152 '$moreNotSupported (web/test.html 8 27)', |
141 '$moreNotSupported (web/test.html 14 15)' | 153 '$moreNotSupported (web/test.html 16 15)' |
142 ]); | 154 ]); |
143 | 155 |
144 testPhases('with imports', phases, { | 156 testPhases('with imports', phases, { |
145 'a|web/index.html': | 157 'a|web/index.html': |
146 '<!DOCTYPE html><html><head>' | 158 '<!DOCTYPE html><html><head>' |
147 '<link rel="import" href="test2.html">' | 159 '<link rel="import" href="test2.html">' |
148 '</head><body>' | 160 '</head><body>' |
149 '<script type="application/dart" src="b.dart"></script>', | 161 '<script type="application/dart" src="b.dart"></script>', |
150 'a|web/b.dart': _sampleObservable('B', 'bar'), | 162 'a|web/b.dart': _sampleObservable('B', 'bar'), |
151 'a|web/test2.html': | 163 'a|web/test2.html': |
152 '<!DOCTYPE html><html><head></head><body>' | 164 '<!DOCTYPE html><html><head></head><body>' |
153 '<polymer-element name="x-a">1' | 165 '<polymer-element name="x-a">1' |
154 '<script type="application/dart">' | 166 '<script type="application/dart">' |
155 '${_sampleObservable("A", "foo")}</script>' | 167 '${_sampleObservable("A", "foo")}</script>' |
156 '</polymer-element></html>', | 168 '</polymer-element></html>', |
157 }, { | 169 }, { |
158 'a|web/index.html': | 170 'a|web/index.html': |
159 '<!DOCTYPE html><html><head>' | 171 '<!DOCTYPE html><html><head>' |
160 '$WEB_COMPONENTS_TAG' | 172 '$WEB_COMPONENTS_TAG' |
161 '$INTEROP_TAG' | 173 '$INTEROP_TAG' |
162 '</head><body><polymer-element name="x-a">1</polymer-element>' | 174 '</head><body><polymer-element name="x-a">1</polymer-element>' |
163 '<script src="index.html_bootstrap.dart.js"></script>' | 175 '<script src="index.html_bootstrap.dart.js"></script>' |
164 '</body></html>', | 176 '</body></html>', |
165 'a|web/index.html_bootstrap.dart': | 177 'a|web/index.html_bootstrap.dart': |
166 '''$MAIN_HEADER | 178 '''$MAIN_HEADER |
167 import 'index.html.0.dart' as i0; | 179 import 'index.html.0.dart' as i0; |
168 import 'b.dart' as i1; | 180 import 'b.dart' as i1; |
| 181 ${DEFAULT_IMPORTS.join('\n')} |
169 | 182 |
170 void main() { | 183 void main() { |
| 184 useGeneratedCode(new StaticConfiguration( |
| 185 checkedMode: false)); |
171 configureForDeployment([ | 186 configureForDeployment([ |
172 ]); | 187 ]); |
173 i1.main(); | 188 i1.main(); |
174 } | 189 } |
175 '''.replaceAll('\n ', '\n'), | 190 '''.replaceAll('\n ', '\n'), |
176 'a|web/index.html.0.dart': _sampleObservableOutput("A", "foo"), | 191 'a|web/index.html.0.dart': _sampleObservableOutput("A", "foo"), |
177 'a|web/b.dart': _sampleObservableOutput('B', 'bar'), | 192 'a|web/b.dart': _sampleObservableOutput('B', 'bar'), |
178 }); | 193 }); |
179 } | 194 } |
180 | 195 |
181 String _sampleObservable(String className, String fieldName) => ''' | 196 String _sampleObservable(String className, String fieldName) => ''' |
182 library ${className}_$fieldName; | 197 library ${className}_$fieldName; |
183 import 'package:observe/observe.dart'; | 198 import 'package:observe/observe.dart'; |
| 199 export 'package:polymer/init.dart'; |
184 | 200 |
185 class $className extends Observable { | 201 class $className extends Observable { |
186 @observable int $fieldName; | 202 @observable int $fieldName; |
187 $className(this.$fieldName); | 203 $className(this.$fieldName); |
188 } | 204 } |
189 '''; | 205 '''; |
190 | 206 |
191 String _sampleObservableOutput(String className, String field, | 207 String _sampleObservableOutput(String className, String field, |
192 {bool includeMain: false}) => | 208 {bool includeMain: false}) => |
193 "library ${className}_$field;\n" | 209 "library ${className}_$field;\n" |
194 "import 'package:observe/observe.dart';\n\n" | 210 "import 'package:observe/observe.dart';\n" |
| 211 "export 'package:polymer/init.dart';\n\n" |
195 "class $className extends ChangeNotifier {\n" | 212 "class $className extends ChangeNotifier {\n" |
196 " @reflectable @observable int get $field => __\$$field; " | 213 " @reflectable @observable int get $field => __\$$field; " |
197 "int __\$$field; " | 214 "int __\$$field; " |
198 "@reflectable set $field(int value) { " | 215 "@reflectable set $field(int value) { " |
199 "__\$$field = notifyPropertyChange(#$field, __\$$field, value); " | 216 "__\$$field = notifyPropertyChange(#$field, __\$$field, value); " |
200 "}\n" | 217 "}\n" |
201 " $className($field) : __\$$field = $field;\n" | 218 " $className($field) : __\$$field = $field;\n" |
202 "}\n"; | 219 "}\n"; |
OLD | NEW |