OLD | NEW |
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'; |
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.changeExtension('.vm_test.dart')); | 22 transform.declareOutput(id.addExtension('.vm_test.dart')); |
23 transform.declareOutput(id.changeExtension('.browser_test.dart')); | 23 transform.declareOutput(id.addExtension('.browser_test.dart')); |
24 transform.declareOutput(id.changeExtension('.browser_test.html')); | 24 transform.declareOutput(id.addExtension('.browser_test.html')); |
25 } | 25 } |
26 | 26 |
27 void apply(Transform transform) { | 27 void 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.changeExtension('.vm_test.dart'), ''' | 31 new Asset.fromString(id.addExtension('.vm_test.dart'), ''' |
32 import "package:test/src/runner/vm/isolate_listener.dart"; | 32 import "package:test/src/runner/vm/isolate_listener.dart"; |
33 | 33 |
34 import "${p.url.basename(id.path)}" as test; | 34 import "${p.url.basename(id.path)}" as test; |
35 | 35 |
36 void main(_, Map message) { | 36 void main(_, Map message) { |
37 var sendPort = message['reply']; | 37 var sendPort = message['reply']; |
38 IsolateListener.start(sendPort, () => test.main); | 38 IsolateListener.start(sendPort, () => test.main); |
39 } | 39 } |
40 ''')); | 40 ''')); |
41 | 41 |
42 var browserId = id.changeExtension('.browser_test.dart'); | 42 var browserId = id.addExtension('.browser_test.dart'); |
43 transform.addOutput(new Asset.fromString(browserId, ''' | 43 transform.addOutput(new Asset.fromString(browserId, ''' |
44 import "package:test/src/runner/browser/iframe_listener.dart"; | 44 import "package:test/src/runner/browser/iframe_listener.dart"; |
45 | 45 |
46 import "${p.url.basename(id.path)}" as test; | 46 import "${p.url.basename(id.path)}" as test; |
47 | 47 |
48 void main(_) { | 48 void main(_) { |
49 IframeListener.start(() => test.main); | 49 IframeListener.start(() => test.main); |
50 } | 50 } |
51 ''')); | 51 ''')); |
52 | 52 |
53 transform.addOutput( | 53 transform.addOutput( |
54 new Asset.fromString(browserId.changeExtension('.html'), ''' | 54 new Asset.fromString(id.addExtension('.browser_test.html'), ''' |
55 <!DOCTYPE html> | 55 <!DOCTYPE html> |
56 <html> | 56 <html> |
57 <head> | 57 <head> |
58 <title>${HTML_ESCAPE.convert(id.path)} Test</title> | 58 <title>${HTML_ESCAPE.convert(id.path)} Test</title> |
59 <script src="${HTML_ESCAPE.convert(p.url.basename(browserId.path))}.js"> | 59 <script src="${HTML_ESCAPE.convert(p.url.basename(browserId.path))}.js"> |
60 </script> | 60 </script> |
61 </head> | 61 </head> |
62 </html> | 62 </html> |
63 ''')); | 63 ''')); |
64 } | 64 } |
65 } | 65 } |
OLD | NEW |