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 ManyToOneTransformer.asPlugin(); | |
19 | |
20 String classifyPrimary(AssetId id) { | |
21 if (id.extension != '.txt') return null; | |
22 return p.url.dirname(id.path); | |
23 } | |
24 | |
25 Future apply(AggregateTransform transform) { | |
26 return transform.primaryInputs.toList().then((assets) { | |
27 assets.sort((asset1, asset2) => asset1.id.path.compareTo(asset2.id.path)); | |
28 return Future.wait(assets.map((asset) => asset.readAsString())); | |
29 }).then((contents) { | |
30 var id = new AssetId(transform.package, | |
31 p.url.join(transform.key, 'out.txt')); | |
32 transform.addOutput(new Asset.fromString(id, contents.join('\\n'))); | |
33 }); | |
34 } | |
35 } | |
36 """; | |
37 | |
38 main() { | |
39 initConfig(); | |
40 withBarbackVersions(">=0.14.1", () { | |
41 integration("works on an aggregate transformer", () { | |
42 d.dir(appPath, [ | |
43 d.pubspec({ | |
44 "name": "myapp", | |
45 "transformers": [ | |
46 { | |
47 "myapp": { | |
48 "\$include": ["web/a.txt", "web/b.txt", "web/c.txt"], | |
49 "\$exclude": "web/a.txt" | |
50 } | |
51 } | |
52 ] | |
53 }), | |
54 d.dir("lib", [ | |
55 d.file("transformer.dart", AGGREGATE_TRANSFORMER), | |
56 ]), | |
57 d.dir("web", [ | |
58 d.file("a.txt", "a"), | |
59 d.file("b.txt", "b"), | |
60 d.file("c.txt", "c"), | |
61 d.file("d.txt", "d") | |
62 ]) | |
63 ]).create(); | |
64 | |
65 createLockFile('myapp', pkg: ['barback']); | |
66 | |
67 pubServe(); | |
68 requestShouldSucceed("out.txt", "b\nc"); | |
69 endPubServe(); | |
70 }); | |
71 }); | |
72 } | |
OLD | NEW |