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

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: Code review changes 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:async';
5 import 'dart:convert'; 6 import 'dart:convert';
6 7
7 import 'package:barback/barback.dart'; 8 import 'package:barback/barback.dart';
8 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
9 10
10 /// A transformer that injects bootstrapping code used by the test runner to run 11 /// A transformer that injects bootstrapping code used by the test runner to run
11 /// tests against a "pub serve" instance. 12 /// tests against a "pub serve" instance.
12 /// 13 ///
13 /// This doesn't modify existing code at all, it just adds wrapper files that 14 /// This doesn't modify existing code at all, it just adds wrapper files that
14 /// can be used to load isolates or iframes. 15 /// can be used to load isolates or iframes.
15 class PubServeTransformer extends Transformer implements DeclaringTransformer { 16 class PubServeTransformer extends Transformer implements DeclaringTransformer {
16 final allowedExtensions = ".dart"; 17 final allowedExtensions = ".dart";
17 18
18 PubServeTransformer.asPlugin(); 19 PubServeTransformer.asPlugin();
19 20
20 void declareOutputs(DeclaringTransform transform) { 21 void declareOutputs(DeclaringTransform transform) {
21 var id = transform.primaryId; 22 var id = transform.primaryId;
22 transform.declareOutput(id.addExtension('.vm_test.dart')); 23 transform.declareOutput(id.addExtension('.vm_test.dart'));
23 transform.declareOutput(id.addExtension('.browser_test.dart')); 24 transform.declareOutput(id.addExtension('.browser_test.dart'));
24 transform.declareOutput(id.addExtension('.browser_test.html')); 25 transform.declareOutput(id.changeExtension('.html'));
25 } 26 }
26 27
27 void apply(Transform transform) { 28 Future apply(Transform transform) {
28 var id = transform.primaryInput.id; 29 var id = transform.primaryInput.id;
29 30
30 transform.addOutput( 31 transform.addOutput(
31 new Asset.fromString(id.addExtension('.vm_test.dart'), ''' 32 new Asset.fromString(id.addExtension('.vm_test.dart'), '''
32 import "package:test/src/backend/metadata.dart"; 33 import "package:test/src/backend/metadata.dart";
33 import "package:test/src/runner/vm/isolate_listener.dart"; 34 import "package:test/src/runner/vm/isolate_listener.dart";
34 35
35 import "${p.url.basename(id.path)}" as test; 36 import "${p.url.basename(id.path)}" as test;
36 37
37 void main(_, Map message) { 38 void main(_, Map message) {
38 var sendPort = message['reply']; 39 var sendPort = message['reply'];
39 var metadata = new Metadata.deserialize(message['metadata']); 40 var metadata = new Metadata.deserialize(message['metadata']);
40 IsolateListener.start(sendPort, metadata, () => test.main); 41 IsolateListener.start(sendPort, metadata, () => test.main);
41 } 42 }
42 ''')); 43 '''));
43 44
44 var browserId = id.addExtension('.browser_test.dart'); 45 transform.addOutput(
45 transform.addOutput(new Asset.fromString(browserId, ''' 46 new Asset.fromString(id.addExtension('.browser_test.dart'), '''
46 import "package:test/src/runner/browser/iframe_listener.dart"; 47 import "package:test/src/runner/browser/iframe_listener.dart";
47 48
48 import "${p.url.basename(id.path)}" as test; 49 import "${p.url.basename(id.path)}" as test;
49 50
50 void main(_) { 51 void main() {
51 IframeListener.start(() => test.main); 52 IframeListener.start(() => test.main);
52 } 53 }
53 ''')); 54 '''));
54 55
55 transform.addOutput( 56 // If the user has their own HTML file for the test, let that take
56 new Asset.fromString(id.addExtension('.browser_test.html'), ''' 57 // precedence. Otherwise, create our own basic file.
58 var htmlId = id.changeExtension('.html');
59 return transform.hasInput(htmlId).then((hasInput) {
60 if (hasInput) return;
61 transform.addOutput(
62 new Asset.fromString(htmlId, '''
57 <!DOCTYPE html> 63 <!DOCTYPE html>
58 <html> 64 <html>
59 <head> 65 <head>
60 <title>${HTML_ESCAPE.convert(id.path)} Test</title> 66 <title>${HTML_ESCAPE.convert(id.path)} Test</title>
61 <script src="${HTML_ESCAPE.convert(p.url.basename(browserId.path))}.js"> 67 <link rel="x-dart-test" href="${HTML_ESCAPE.convert(p.url.basename(id.path))}" >
62 </script> 68 <script src="packages/test/dart.js"></script>
63 </head> 69 </head>
64 </html> 70 </html>
65 ''')); 71 '''));
72 });
66 } 73 }
67 } 74 }
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