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 '../serve/utils.dart'; | |
10 | |
11 const AGGREGATE_TRANSFORMER = """ | |
12 import 'dart:async'; | |
13 | |
14 import 'package:barback/barback.dart'; | |
15 import 'package:path/path.dart' as p; | |
16 | |
17 class ManyToOneTransformer extends AggregateTransformer | |
18 implements DeclaringAggregateTransformer { | |
19 ManyToOneTransformer.asPlugin(); | |
20 | |
21 String classifyPrimary(AssetId id) { | |
22 if (id.extension != '.out') return null; | |
23 return p.url.dirname(id.path); | |
24 } | |
25 | |
26 Future apply(AggregateTransform transform) { | |
27 return transform.primaryInputs.toList().then((assets) { | |
28 assets.sort((asset1, asset2) => asset1.id.path.compareTo(asset2.id.path)); | |
29 return Future.wait(assets.map((asset) => asset.readAsString())); | |
30 }).then((contents) { | |
31 var id = new AssetId(transform.package, | |
32 p.url.join(transform.key, 'out.final')); | |
33 transform.addOutput(new Asset.fromString(id, contents.join('\\n'))); | |
34 }); | |
35 } | |
36 | |
37 void declareOutputs(DeclaringAggregateTransform transform) { | |
38 transform.declareOutput(new AssetId(transform.package, | |
39 p.url.join(transform.key, 'out.final'))); | |
40 } | |
41 } | |
42 """; | |
43 | |
44 main() { | |
45 initConfig(); | |
46 withBarbackVersions(">=0.14.1", () { | |
47 integration("loads a declaring aggregate transformer", () { | |
48 d.dir(appPath, [d.pubspec({ | |
49 "name": "myapp", | |
50 "transformers": ["myapp/lazy", "myapp/aggregate"] | |
51 }), | |
52 d.dir( | |
53 "lib", | |
54 [ | |
55 d.file("lazy.dart", LAZY_TRANSFORMER), | |
56 d.file("aggregate.dart", AGGREGATE_TRANSFORMER),]), | |
57 d.dir("web", [d.file("foo.txt", "foo"), d.file("bar.txt", "bar")])])
.create(); | |
58 | |
59 createLockFile('myapp', pkg: ['barback']); | |
60 | |
61 var server = pubServe(); | |
62 // The transformer should preserve laziness. | |
63 server.stdout.expect("Build completed successfully"); | |
64 | |
65 requestShouldSucceed("out.final", "bar.out\nfoo.out"); | |
66 endPubServe(); | |
67 }); | |
68 }); | |
69 } | |
OLD | NEW |