| 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 | 4 |
| 5 /// A tool to gather coverage data from an app generated with dart2js. This | 5 /// A tool to gather coverage data from an app generated with dart2js. This |
| 6 /// depends on code that has been landed in the bleeding_edge version of dart2js | 6 /// depends on code that has been landed in the bleeding_edge version of dart2js |
| 7 /// and that we expect to become publicly visible in version 0.13.0 of the Dart | 7 /// and that we expect to become publicly visible in version 0.13.0 of the Dart |
| 8 /// SDK). | 8 /// SDK). |
| 9 /// | 9 /// |
| 10 /// This tool starts a server that answers to mainly 2 requests: | 10 /// This tool starts a server that answers to mainly 2 requests: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import 'dart:convert'; | 22 import 'dart:convert'; |
| 23 import 'dart:io'; | 23 import 'dart:io'; |
| 24 import 'dart:async'; | 24 import 'dart:async'; |
| 25 import 'package:path/path.dart' as path; | 25 import 'package:path/path.dart' as path; |
| 26 import 'package:args/args.dart'; | 26 import 'package:args/args.dart'; |
| 27 import 'package:shelf/shelf.dart' as shelf; | 27 import 'package:shelf/shelf.dart' as shelf; |
| 28 import 'package:shelf/shelf_io.dart' as shelf; | 28 import 'package:shelf/shelf_io.dart' as shelf; |
| 29 | 29 |
| 30 const _DEFAULT_OUT_TEMPLATE = '<dart2js-out-file>.coverage.json'; | 30 const _DEFAULT_OUT_TEMPLATE = '<dart2js-out-file>.coverage.json'; |
| 31 | 31 |
| 32 main(argv) async { | 32 main(List<String> argv) async { |
| 33 var parser = new ArgParser() | 33 var parser = new ArgParser() |
| 34 ..addOption('port', abbr: 'p', help: 'port number', defaultsTo: "8080") | 34 ..addOption('port', abbr: 'p', help: 'port number', defaultsTo: "8080") |
| 35 ..addOption('host', | 35 ..addOption('host', |
| 36 help: 'host name (use 0.0.0.0 for all interfaces)', | 36 help: 'host name (use 0.0.0.0 for all interfaces)', |
| 37 defaultsTo: 'localhost') | 37 defaultsTo: 'localhost') |
| 38 ..addFlag('help', | 38 ..addFlag('help', |
| 39 abbr: 'h', help: 'show this help message', negatable: false) | 39 abbr: 'h', help: 'show this help message', negatable: false) |
| 40 ..addOption('uri-prefix', | 40 ..addOption('uri-prefix', |
| 41 help: 'uri path prefix that will hit this server. This will be injected' | 41 help: 'uri path prefix that will hit this server. This will be injected' |
| 42 ' into the .js file', | 42 ' into the .js file', |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool _savePending = false; | 164 bool _savePending = false; |
| 165 int _total = 0; | 165 int _total = 0; |
| 166 _enqueueSave() async { | 166 _enqueueSave() async { |
| 167 if (!_savePending) { | 167 if (!_savePending) { |
| 168 _savePending = true; | 168 _savePending = true; |
| 169 await new Future.delayed(new Duration(seconds: 3)); | 169 await new Future.delayed(new Duration(seconds: 3)); |
| 170 await new File(outPath).writeAsString(_serializedData); | 170 await new File(outPath).writeAsString(_serializedData); |
| 171 var diff = data.length - _total; | 171 var diff = data.length - _total; |
| 172 print( | 172 print(diff == 0 |
| 173 diff ? ' - no new element covered' : ' - $diff new elements covered'); | 173 ? ' - no new element covered' |
| 174 : ' - $diff new elements covered'); |
| 174 _savePending = false; | 175 _savePending = false; |
| 175 _total = data.length; | 176 _total = data.length; |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 | 180 |
| 180 /// Removes leading and trailing slashes of [uriPath]. | 181 /// Removes leading and trailing slashes of [uriPath]. |
| 181 _normalize(String uriPath) { | 182 _normalize(String uriPath) { |
| 182 if (uriPath.startsWith('/')) uriPath = uriPath.substring(1); | 183 if (uriPath.startsWith('/')) uriPath = uriPath.substring(1); |
| 183 if (uriPath.endsWith('/')) uriPath = uriPath.substring(0, uriPath.length - 1); | 184 if (uriPath.endsWith('/')) uriPath = uriPath.substring(0, uriPath.length - 1); |
| 184 return uriPath; | 185 return uriPath; |
| 185 } | 186 } |
| 186 | 187 |
| 187 _adjustRequestUrl(String code, String prefix) { | 188 _adjustRequestUrl(String code, String prefix) { |
| 188 var newUrl = prefix == '' ? 'coverage' : '$prefix/coverage'; | 189 var newUrl = prefix == '' ? 'coverage' : '$prefix/coverage'; |
| 189 return code.replaceFirst('"/coverage_uri_to_amend_by_server"', | 190 return code.replaceFirst('"/coverage_uri_to_amend_by_server"', |
| 190 '"/$newUrl" /*url-prefix updated!*/'); | 191 '"/$newUrl" /*url-prefix updated!*/'); |
| 191 } | 192 } |
| 192 | 193 |
| 193 const HTML_HEADERS = const {'content-type': 'text/html'}; | 194 const HTML_HEADERS = const {'content-type': 'text/html'}; |
| 194 const JS_HEADERS = const {'content-type': 'text/javascript'}; | 195 const JS_HEADERS = const {'content-type': 'text/javascript'}; |
| 195 const TEXT_HEADERS = const {'content-type': 'text/plain'}; | 196 const TEXT_HEADERS = const {'content-type': 'text/plain'}; |
| OLD | NEW |