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

Side by Side Diff: lib/pub_serve.dart

Issue 1087303004: Add support for user-defined HTML files. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « lib/dart.js ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:convert'; 5 import 'dart:convert';
kevmoo 2015/04/17 22:09:29 Need dart:async
nweiz 2015/04/17 22:10:59 Done.
6 6
7 import 'package:barback/barback.dart'; 7 import 'package:barback/barback.dart';
8 import 'package:path/path.dart' as p; 8 import 'package:path/path.dart' as p;
9 9
10 /// A transformer that injects bootstrapping code used by the test runner to run 10 /// A transformer that injects bootstrapping code used by the test runner to run
11 /// tests against a "pub serve" instance. 11 /// tests against a "pub serve" instance.
12 /// 12 ///
13 /// This doesn't modify existing code at all, it just adds wrapper files that 13 /// This doesn't modify existing code at all, it just adds wrapper files that
14 /// can be used to load isolates or iframes. 14 /// can be used to load isolates or iframes.
15 class PubServeTransformer extends Transformer implements DeclaringTransformer { 15 class PubServeTransformer extends Transformer implements DeclaringTransformer {
16 final allowedExtensions = ".dart"; 16 final allowedExtensions = ".dart";
17 17
18 PubServeTransformer.asPlugin(); 18 PubServeTransformer.asPlugin();
19 19
20 void declareOutputs(DeclaringTransform transform) { 20 void declareOutputs(DeclaringTransform transform) {
21 var id = transform.primaryId; 21 var id = transform.primaryId;
22 transform.declareOutput(id.addExtension('.vm_test.dart')); 22 transform.declareOutput(id.addExtension('.vm_test.dart'));
23 transform.declareOutput(id.addExtension('.browser_test.dart')); 23 transform.declareOutput(id.addExtension('.browser_test.dart'));
24 transform.declareOutput(id.addExtension('.browser_test.html')); 24 transform.declareOutput(id.changeExtension('.html'));
25 } 25 }
26 26
27 void apply(Transform transform) { 27 Future apply(Transform transform) {
28 var id = transform.primaryInput.id; 28 var id = transform.primaryInput.id;
29 29
30 transform.addOutput( 30 transform.addOutput(
31 new Asset.fromString(id.addExtension('.vm_test.dart'), ''' 31 new Asset.fromString(id.addExtension('.vm_test.dart'), '''
32 import "package:test/src/backend/metadata.dart"; 32 import "package:test/src/backend/metadata.dart";
33 import "package:test/src/runner/vm/isolate_listener.dart"; 33 import "package:test/src/runner/vm/isolate_listener.dart";
34 34
35 import "${p.url.basename(id.path)}" as test; 35 import "${p.url.basename(id.path)}" as test;
36 36
37 void main(_, Map message) { 37 void main(_, Map message) {
38 var sendPort = message['reply']; 38 var sendPort = message['reply'];
39 var metadata = new Metadata.deserialize(message['metadata']); 39 var metadata = new Metadata.deserialize(message['metadata']);
40 IsolateListener.start(sendPort, metadata, () => test.main); 40 IsolateListener.start(sendPort, metadata, () => test.main);
41 } 41 }
42 ''')); 42 '''));
43 43
44 var browserId = id.addExtension('.browser_test.dart'); 44 transform.addOutput(
45 transform.addOutput(new Asset.fromString(browserId, ''' 45 new Asset.fromString(id.addExtension('.browser_test.dart'), '''
46 import "package:test/src/runner/browser/iframe_listener.dart"; 46 import "package:test/src/runner/browser/iframe_listener.dart";
47 47
48 import "${p.url.basename(id.path)}" as test; 48 import "${p.url.basename(id.path)}" as test;
49 49
50 void main(_) { 50 void main() {
51 IframeListener.start(() => test.main); 51 IframeListener.start(() => test.main);
52 } 52 }
53 ''')); 53 '''));
54 54
55 transform.addOutput( 55 // If the user has their own HTML file for the test, let that take
56 new Asset.fromString(id.addExtension('.browser_test.html'), ''' 56 // precedence. Otherwise, create our own basic file.
57 var htmlId = id.changeExtension('.html');
58 return transform.hasInput(htmlId).then((hasInput) {
59 if (hasInput) return;
60 transform.addOutput(
61 new Asset.fromString(htmlId, '''
57 <!DOCTYPE html> 62 <!DOCTYPE html>
58 <html> 63 <html>
59 <head> 64 <head>
60 <title>${HTML_ESCAPE.convert(id.path)} Test</title> 65 <title>${HTML_ESCAPE.convert(id.path)} Test</title>
61 <script src="${HTML_ESCAPE.convert(p.url.basename(browserId.path))}.js"> 66 <link rel="x-dart-test" href="${HTML_ESCAPE.convert(p.url.basename(id.path))}" >
62 </script> 67 <script src="packages/test/dart.js"></script>
63 </head> 68 </head>
64 </html> 69 </html>
65 ''')); 70 '''));
71 });
66 } 72 }
67 } 73 }
OLDNEW
« no previous file with comments | « lib/dart.js ('k') | lib/src/runner/browser/server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698