Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: lib/pub_serve.dart

Issue 1062523003: Add support for --pub-serve. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.md ('k') | lib/src/executable.dart » ('j') | lib/src/util/io.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/pub_serve.dart
diff --git a/lib/pub_serve.dart b/lib/pub_serve.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f7cf373224829a29cb3e78ad8c2785eae9674032
--- /dev/null
+++ b/lib/pub_serve.dart
@@ -0,0 +1,65 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:convert';
+
+import 'package:barback/barback.dart';
+import 'package:path/path.dart' as p;
+
+/// A transformer that injects bootstrapping code used by the test runner to run
+/// tests against a "pub serve" instance.
+///
+/// This doesn't modify existing code at all, it just adds wrapper files that
+/// can be used to load isolates or iframes.
+class PubServeTransformer extends Transformer implements DeclaringTransformer {
+ final allowedExtensions = ".dart";
+
+ PubServeTransformer.asPlugin();
+
+ void declareOutputs(DeclaringTransform transform) {
+ var id = transform.primaryId;
+ transform.declareOutput(id.changeExtension('.vm_test.dart'));
+ transform.declareOutput(id.changeExtension('.browser_test.dart'));
+ transform.declareOutput(id.changeExtension('.browser_test.html'));
+ }
+
+ void apply(Transform transform) {
+ var id = transform.primaryInput.id;
+
+ transform.addOutput(
+ new Asset.fromString(id.changeExtension('.vm_test.dart'), '''
+import "package:test/src/runner/vm/isolate_listener.dart";
+
+import "${p.url.basename(id.path)}" as test;
+
+void main(_, Map message) {
+ var sendPort = message['reply'];
+ IsolateListener.start(sendPort, () => test.main);
+}
+'''));
+
+ var browserId = id.changeExtension('.browser_test.dart');
+ transform.addOutput(new Asset.fromString(browserId, '''
+import "package:test/src/runner/browser/iframe_listener.dart";
+
+import "${p.url.basename(id.path)}" as test;
+
+void main(_) {
+ IframeListener.start(() => test.main);
+}
+'''));
+
+ transform.addOutput(
+ new Asset.fromString(browserId.changeExtension('.html'), '''
+<!DOCTYPE html>
+<html>
+<head>
+ <title>${HTML_ESCAPE.convert(id.path)} Test</title>
+ <script src="${HTML_ESCAPE.convert(p.url.basename(browserId.path))}.js">
+ </script>
+</head>
+</html>
+'''));
+ }
+}
« no previous file with comments | « README.md ('k') | lib/src/executable.dart » ('j') | lib/src/util/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698