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

Unified Diff: mojo/public/dart/third_party/test/lib/pub_serve.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
Index: mojo/public/dart/third_party/test/lib/pub_serve.dart
diff --git a/mojo/public/dart/third_party/test/lib/pub_serve.dart b/mojo/public/dart/third_party/test/lib/pub_serve.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cf96c135f62f81c66ffe91717cabb111a5fd6f35
--- /dev/null
+++ b/mojo/public/dart/third_party/test/lib/pub_serve.dart
@@ -0,0 +1,72 @@
+// 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:async';
+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.addExtension('.vm_test.dart'));
+ transform.declareOutput(id.addExtension('.browser_test.dart'));
+ }
+
+ Future apply(Transform transform) async {
+ var id = transform.primaryInput.id;
+
+ transform.addOutput(
+ new Asset.fromString(id.addExtension('.vm_test.dart'), '''
+import "package:test/src/backend/metadata.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'];
+ var metadata = new Metadata.deserialize(message['metadata']);
+ IsolateListener.start(sendPort, metadata, () => test.main);
+}
+'''));
+
+ transform.addOutput(
+ new Asset.fromString(id.addExtension('.browser_test.dart'), '''
+import "package:test/src/runner/browser/iframe_listener.dart";
+
+import "${p.url.basename(id.path)}" as test;
+
+void main() {
+ IframeListener.start(() => test.main);
+}
+'''));
+
+ // If the user has their own HTML file for the test, let that take
+ // precedence. Otherwise, create our own basic file.
+ var htmlId = id.changeExtension('.html');
+ if (await transform.hasInput(htmlId)) return;
+
+ transform.addOutput(
+ new Asset.fromString(htmlId, '''
+<!DOCTYPE html>
+<html>
+<head>
+ <title>${HTML_ESCAPE.convert(id.path)} Test</title>
+ <link rel="x-dart-test" href="${HTML_ESCAPE.convert(p.url.basename(id.path))}">
+ <script src="packages/test/dart.js"></script>
+</head>
+</html>
+'''));
+ }
+}
« no previous file with comments | « mojo/public/dart/third_party/test/lib/dart.js ('k') | mojo/public/dart/third_party/test/lib/src/backend/closed_exception.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698