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