OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 import 'utils.dart'; |
| 6 |
5 String getHtmlContents(String title, String scriptType, String scriptPath) { | 7 String getHtmlContents(String title, String scriptType, String scriptPath) { |
6 return """ | 8 return """ |
7 <!DOCTYPE html> | 9 <!DOCTYPE html> |
8 <html> | 10 <html> |
9 <head> | 11 <head> |
10 <meta http-equiv="X-UA-Compatible" content="IE=edge"> | 12 <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
11 <meta name="dart.unittest" content="full-stack-traces"> | 13 <meta name="dart.unittest" content="full-stack-traces"> |
12 <title> Test $title </title> | 14 <title> Test $title </title> |
13 <style> | 15 <style> |
14 .unittest-table { font-family:monospace; border:1px; } | 16 .unittest-table { font-family:monospace; border:1px; } |
(...skipping 16 matching lines...) Expand all Loading... |
31 </body> | 33 </body> |
32 </html>"""; | 34 </html>"""; |
33 } | 35 } |
34 | 36 |
35 /// Generates the HTML template file needed to load and run a dartdevc test in | 37 /// Generates the HTML template file needed to load and run a dartdevc test in |
36 /// the browser. | 38 /// the browser. |
37 /// | 39 /// |
38 /// The [testName] is the short name of the test without any subdirectory path | 40 /// The [testName] is the short name of the test without any subdirectory path |
39 /// or extension, like "math_test". The [testJSDir] is the relative path to the | 41 /// or extension, like "math_test". The [testJSDir] is the relative path to the |
40 /// build directory where the dartdevc-generated JS file is stored. | 42 /// build directory where the dartdevc-generated JS file is stored. |
41 String dartdevcHtml(String testName, String testJSDir) => """ | 43 String dartdevcHtml(String testName, String testJSDir, String buildDir) { |
| 44 var packagePaths = testPackages |
| 45 .map((package) => ' "$package": "/root_dart/$buildDir/gen/utils/' |
| 46 'dartdevc/pkg/$package",') |
| 47 .join("\n"); |
| 48 |
| 49 return """ |
42 <!DOCTYPE html> | 50 <!DOCTYPE html> |
43 <html> | 51 <html> |
44 <head> | 52 <head> |
45 <meta http-equiv="X-UA-Compatible" content="IE=edge"> | 53 <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
46 <meta name="dart.unittest" content="full-stack-traces"> | 54 <meta name="dart.unittest" content="full-stack-traces"> |
47 <title>Test $testName</title> | 55 <title>Test $testName</title> |
48 <style> | 56 <style> |
49 .unittest-table { font-family:monospace; border:1px; } | 57 .unittest-table { font-family:monospace; border:1px; } |
50 .unittest-pass { background: #6b3;} | 58 .unittest-pass { background: #6b3;} |
51 .unittest-fail { background: #d55;} | 59 .unittest-fail { background: #d55;} |
52 .unittest-error { background: #a11;} | 60 .unittest-error { background: #a11;} |
53 </style> | 61 </style> |
54 </head> | 62 </head> |
55 <body> | 63 <body> |
56 <h1>Running $testName</h1> | 64 <h1>Running $testName</h1> |
57 <script type="text/javascript" | 65 <script type="text/javascript" |
58 src="/root_dart/tools/testing/dart/test_controller.js"> | 66 src="/root_dart/tools/testing/dart/test_controller.js"> |
59 </script> | 67 </script> |
60 <script> | 68 <script> |
61 var require = { | 69 var require = { |
62 baseUrl: "/root_dart/$testJSDir", | 70 baseUrl: "/root_dart/$testJSDir", |
63 // TODO(29923): Add paths to the packages that are used in tests once they | |
64 // are being built. Right now, they are compiled into the test module itself. | |
65 paths: { | 71 paths: { |
66 "dart_sdk": "/root_dart/pkg/dev_compiler/lib/js/amd/dart_sdk", | 72 "dart_sdk": "/root_dart/pkg/dev_compiler/lib/js/amd/dart_sdk", |
| 73 $packagePaths |
67 } | 74 } |
68 }; | 75 }; |
69 | 76 |
70 // Don't try to bring up the debugger on a runtime error. | 77 // Don't try to bring up the debugger on a runtime error. |
71 window.ddcSettings = { | 78 window.ddcSettings = { |
72 trapRuntimeErrors: false | 79 trapRuntimeErrors: false |
73 }; | 80 }; |
74 </script> | 81 </script> |
75 <script type="text/javascript" | 82 <script type="text/javascript" |
76 src="/root_dart/third_party/requirejs/require.js"></script> | 83 src="/root_dart/third_party/requirejs/require.js"></script> |
77 <script type="text/javascript"> | 84 <script type="text/javascript"> |
78 requirejs(["$testName", "dart_sdk"], | 85 requirejs(["$testName", "dart_sdk", "async_helper"], |
79 function($testName, dart_sdk) { | 86 function($testName, dart_sdk, async_helper) { |
| 87 function finish() { |
| 88 // dev_compiler's test runner (language_test.js) uses this to notify the |
| 89 // test results, but it isn't needed for test.dart. |
| 90 } |
| 91 |
| 92 // TODO(rnystrom): This uses DDC's forked version of async_helper. Unfork |
| 93 // these packages when possible. |
| 94 async_helper.async_helper.asyncTestInitialize(finish); |
| 95 |
80 dart_sdk._isolate_helper.startRootIsolate(function() {}, []); | 96 dart_sdk._isolate_helper.startRootIsolate(function() {}, []); |
81 dartMainRunner($testName.$testName.main); | 97 dartMainRunner($testName.$testName.main); |
82 }); | 98 }); |
83 </script> | 99 </script> |
84 </body> | 100 </body> |
85 </html> | 101 </html> |
86 """; | 102 """; |
| 103 } |
87 | 104 |
88 String dartTestWrapper(String libraryPathComponent) { | 105 String dartTestWrapper(String libraryPathComponent) { |
89 return """ | 106 return """ |
90 import '$libraryPathComponent' as test; | 107 import '$libraryPathComponent' as test; |
91 | 108 |
92 main() { | 109 main() { |
93 print("dart-calling-main"); | 110 print("dart-calling-main"); |
94 test.main(); | 111 test.main(); |
95 print("dart-main-done"); | 112 print("dart-main-done"); |
96 } | 113 } |
97 """; | 114 """; |
98 } | 115 } |
OLD | NEW |