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 LazyAggregateTransformer { | |
19 ManyToOneTransformer.asPlugin(); | |
20 | |
21 String classifyPrimary(AssetId id) { | |
22 if (id.extension != '.txt') 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.txt')); | |
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.txt'))); | |
40 } | |
41 } | |
42 """; | |
43 | |
44 main() { | |
45 initConfig(); | |
46 withBarbackVersions(">=0.14.1", () { | |
47 integration("loads a lazy aggregate transformer", () { | |
48 d.dir(appPath, [ | |
49 d.pubspec({ | |
50 "name": "myapp", | |
51 "transformers": ["myapp"] | |
52 }), | |
53 d.dir("lib", [ | |
54 d.file("transformer.dart", AGGREGATE_TRANSFORMER), | |
55 ]), | |
56 d.dir("web", [ | |
57 d.file("foo.txt", "foo"), | |
58 d.file("bar.txt", "bar") | |
59 ]) | |
60 ]).create(); | |
61 | |
62 createLockFile('myapp', pkg: ['barback']); | |
63 | |
64 var server = pubServe(); | |
65 // The transformer should preserve laziness. | |
66 server.stdout.expect("Build completed successfully"); | |
67 | |
68 requestShouldSucceed("out.txt", "bar\nfoo"); | |
69 endPubServe(); | |
70 }); | |
71 }); | |
72 } | |
OLD | NEW |