OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file | |
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. | |
4 | |
5 library pub_tests; | |
6 | |
7 import '../descriptor.dart' as d; | |
8 import '../test_pub.dart'; | |
9 import 'utils.dart'; | |
10 | |
11 const DECLARING_TRANSFORMER = """ | |
12 import 'dart:async'; | |
13 | |
14 import 'package:barback/barback.dart'; | |
15 | |
16 class DeclaringRewriteTransformer extends Transformer | |
17 implements DeclaringTransformer { | |
18 DeclaringRewriteTransformer.asPlugin(); | |
19 | |
20 String get allowedExtensions => '.out'; | |
21 | |
22 Future apply(Transform transform) { | |
23 transform.logger.info('Rewriting \${transform.primaryInput.id}.'); | |
24 return transform.primaryInput.readAsString().then((contents) { | |
25 var id = transform.primaryInput.id.changeExtension(".final"); | |
26 transform.addOutput(new Asset.fromString(id, "\$contents.final")); | |
27 }); | |
28 } | |
29 | |
30 Future declareOutputs(DeclaringTransform transform) { | |
31 transform.declareOutput(transform.primaryId.changeExtension(".final")); | |
32 return new Future.value(); | |
33 } | |
34 } | |
35 """; | |
36 | |
37 main() { | |
38 initConfig(); | |
39 withBarbackVersions("any", () { | |
40 integration("supports a user-defined declaring transformer", () { | |
41 d.dir(appPath, [ | |
42 d.pubspec({ | |
43 "name": "myapp", | |
44 "transformers": ["myapp/src/lazy", "myapp/src/declaring"] | |
45 }), | |
46 d.dir("lib", [d.dir("src", [ | |
47 // Include a lazy transformer before the declaring transformer, | |
48 // because otherwise its behavior is indistinguishable from a normal | |
49 // transformer. | |
50 d.file("lazy.dart", LAZY_TRANSFORMER), | |
51 d.file("declaring.dart", DECLARING_TRANSFORMER) | |
52 ])]), | |
53 d.dir("web", [ | |
54 d.file("foo.txt", "foo") | |
55 ]) | |
56 ]).create(); | |
57 | |
58 createLockFile('myapp', pkg: ['barback']); | |
59 | |
60 var server = pubServe(); | |
61 // The build should complete without either transformer logging anything. | |
62 server.stdout.expect('Build completed successfully'); | |
63 | |
64 requestShouldSucceed("foo.final", "foo.out.final"); | |
65 server.stdout.expect(emitsLines( | |
66 '[Info from LazyRewrite]:\n' | |
67 'Rewriting myapp|web/foo.txt.\n' | |
68 '[Info from DeclaringRewrite]:\n' | |
69 'Rewriting myapp|web/foo.out.')); | |
70 endPubServe(); | |
71 }); | |
72 }); | |
73 } | |
OLD | NEW |