Merge pull request #122 from dart-lang/fix-tests
Fix a bunch of broken tests.
diff --git a/lib/src/runner/browser/compiler_pool.dart b/lib/src/runner/browser/compiler_pool.dart
index e264fdc..fae1fc5 100644
--- a/lib/src/runner/browser/compiler_pool.dart
+++ b/lib/src/runner/browser/compiler_pool.dart
@@ -13,6 +13,7 @@
import '../../util/async_thunk.dart';
import '../../util/io.dart';
+import '../../utils.dart';
import '../load_exception.dart';
/// A pool of `dart2js` instances.
diff --git a/lib/src/runner/browser/server.dart b/lib/src/runner/browser/server.dart
index fe5e0d8..716da34 100644
--- a/lib/src/runner/browser/server.dart
+++ b/lib/src/runner/browser/server.dart
@@ -305,16 +305,20 @@
print('"pub serve" is compiling $path...');
});
+ var mapUrl = jsUrl.replace(path: jsUrl.path + '.map');
var response;
try {
// Get the source map here for two reasons. We want to verify that the
// server's dart2js compiler is running on the Dart code, and also load
// the StackTraceMapper.
- var mapUrl = jsUrl.replace(path: jsUrl.path + '.map');
- var request = await _http.headUrl(mapUrl);
+ var request = await _http.getUrl(mapUrl);
response = await request.close();
if (response.statusCode != 200) {
+ // We don't care about the response body, but we have to drain it or
+ // else the process can't exit.
+ response.listen((_) {});
+
throw new LoadException(path,
"Error getting $mapUrl: ${response.statusCode} "
"${response.reasonPhrase}\n"
@@ -322,8 +326,7 @@
}
if (_jsTrace) {
- // We don't care about the response body, but we have to drain it or
- // else the process can't exit.
+ // Drain the response stream.
response.listen((_) {});
return;
}
diff --git a/test/runner/pub_serve_test.dart b/test/runner/pub_serve_test.dart
index 32c0396..973fcda 100644
--- a/test/runner/pub_serve_test.dart
+++ b/test/runner/pub_serve_test.dart
@@ -54,8 +54,6 @@
Future apply(Transform transform) async {
var contents = await transform.primaryInput.readAsString();
- print("contents: \$contents");
- print("new contents: \${contents.replaceAll("isFalse", "isTrue")}");
transform.addOutput(new Asset.fromString(
transform.primaryInput.id,
contents.replaceAll("isFalse", "isTrue")));
@@ -79,6 +77,18 @@
});
group("with transformed tests", () {
+ setUp(() {
+ // Give the test a failing assertion that the transformer will convert to
+ // a passing assertion.
+ new File(p.join(_sandbox, "test", "my_test.dart")).writeAsStringSync("""
+import 'package:test/test.dart';
+
+void main() {
+ test("test", () => expect(true, isFalse));
+}
+""");
+ });
+
test("runs those tests in the VM", () async {
var pair = await startPubServe(workingDirectory: _sandbox);
try {
@@ -249,56 +259,40 @@
""");
});
- test("dartifies stack traces for JS-compiled tests by default", () {
- return startPub(['serve', '--port', '0'], workingDirectory: _sandbox)
- .then((process) {
- return _lines.bind(process.stdout)
- .firstWhere(_servingRegExp.hasMatch)
- .then((line) {
- var match = _servingRegExp.firstMatch(line);
-
- try {
- var result = runTest([
- '--pub-serve=${match[1]}',
- '-p', 'chrome',
- '--verbose-trace'
- ], workingDirectory: _sandbox);
- expect(result.stdout, contains(" main.<fn>\n"));
- expect(result.stdout, contains("package:test"));
- expect(result.stdout, contains("dart:async/zone.dart"));
- expect(result.exitCode, equals(1));
- } finally {
- process.kill();
- }
- });
- });
+ test("dartifies stack traces for JS-compiled tests by default", () async {
+ var pair = await startPubServe(workingDirectory: _sandbox);
+ try {
+ var result = runTest([
+ '--pub-serve=${pair.last}',
+ '-p', 'chrome',
+ '--verbose-trace'
+ ], workingDirectory: _sandbox);
+ expect(result.stdout, contains(" main.<fn>\n"));
+ expect(result.stdout, contains("package:test"));
+ expect(result.stdout, contains("dart:async/zone.dart"));
+ expect(result.exitCode, equals(1));
+ } finally {
+ pair.first.kill();
+ }
});
test("doesn't dartify stack traces for JS-compiled tests with --js-trace",
- () {
- return startPub(['serve', '--port', '0'], workingDirectory: _sandbox)
- .then((process) {
- return _lines.bind(process.stdout)
- .firstWhere(_servingRegExp.hasMatch)
- .then((line) {
- var match = _servingRegExp.firstMatch(line);
-
- try {
- var result = runTest([
- '--pub-serve=${match[1]}',
- '-p', 'chrome',
- '--js-trace',
- '--verbose-trace'
- ], workingDirectory: _sandbox);
- expect(result.stdout, isNot(contains(" main.<fn>\n")));
- expect(result.stdout, isNot(contains("package:test")));
- expect(result.stdout, isNot(contains("dart:async/zone.dart")));
- expect(result.exitCode, equals(1));
- } finally {
- process.kill();
- }
- });
- });
+ () async {
+ var pair = await startPubServe(workingDirectory: _sandbox);
+ try {
+ var result = runTest([
+ '--pub-serve=${pair.last}',
+ '-p', 'chrome',
+ '--js-trace',
+ '--verbose-trace'
+ ], workingDirectory: _sandbox);
+ expect(result.stdout, isNot(contains(" main.<fn>\n")));
+ expect(result.stdout, isNot(contains("package:test")));
+ expect(result.stdout, isNot(contains("dart:async/zone.dart")));
+ expect(result.exitCode, equals(1));
+ } finally {
+ pair.first.kill();
+ }
});
});
@@ -326,7 +320,7 @@
contains('-1: load error'),
contains('Failed to load "${p.join("test", "my_test.dart")}":'),
contains('Error getting http://localhost:54321/my_test.dart.browser_test'
- '.dart.js: $message'),
+ '.dart.js.map: $message'),
contains('Make sure "pub serve" is running.')
]));
expect(result.exitCode, equals(1));
diff --git a/test/runner/runner_test.dart b/test/runner/runner_test.dart
index 46c10bc..21794bb 100644
--- a/test/runner/runner_test.dart
+++ b/test/runner/runner_test.dart
@@ -65,6 +65,7 @@
[expanded] A separate line for each update.
--verbose-trace Whether to emit stack traces with core library frames.
+ --js-trace Whether to emit raw JavaScript stack traces for browser tests.
--[no-]color Whether to use terminal colors.
(auto-detected by default)
""";