OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, 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 'dart:convert'; | |
8 | |
9 import '../../descriptor.dart' as d; | |
10 import '../../test_pub.dart'; | |
11 import '../../serve/utils.dart'; | |
12 | |
13 final transformer = """ | |
14 import 'dart:async'; | |
15 import 'dart:convert'; | |
16 | |
17 import 'package:barback/barback.dart'; | |
18 | |
19 class ConfigTransformer extends Transformer { | |
20 final BarbackSettings settings; | |
21 | |
22 ConfigTransformer.asPlugin(this.settings); | |
23 | |
24 String get allowedExtensions => '.txt'; | |
25 | |
26 Future apply(Transform transform) { | |
27 return transform.primaryInput.readAsString().then((contents) { | |
28 var id = transform.primaryInput.id.changeExtension(".json"); | |
29 transform.addOutput( | |
30 new Asset.fromString(id, JSON.encode(settings.configuration))); | |
31 }); | |
32 } | |
33 } | |
34 | |
35 class RewriteTransformer extends Transformer { | |
36 RewriteTransformer.asPlugin(); | |
37 | |
38 String get allowedExtensions => '.txt'; | |
39 | |
40 Future apply(Transform transform) { | |
41 return transform.primaryInput.readAsString().then((contents) { | |
42 var id = transform.primaryInput.id.changeExtension(".out"); | |
43 transform.addOutput(new Asset.fromString(id, "\$contents.out")); | |
44 }); | |
45 } | |
46 } | |
47 """; | |
48 | |
49 main() { | |
50 initConfig(); | |
51 withBarbackVersions("any", () { | |
52 integration("with configuration, only instantiates configurable " | |
53 "transformers", () { | |
54 var configuration = {"param": ["list", "of", "values"]}; | |
55 | |
56 d.dir(appPath, [ | |
57 d.pubspec({ | |
58 "name": "myapp", | |
59 "transformers": [{"myapp/src/transformer": configuration}] | |
60 }), | |
61 d.dir("lib", [d.dir("src", [ | |
62 d.file("transformer.dart", transformer) | |
63 ])]), | |
64 d.dir("web", [ | |
65 d.file("foo.txt", "foo") | |
66 ]) | |
67 ]).create(); | |
68 | |
69 createLockFile('myapp', pkg: ['barback']); | |
70 | |
71 var server = pubServe(); | |
72 requestShouldSucceed("foo.json", JSON.encode(configuration)); | |
73 requestShould404("foo.out"); | |
74 endPubServe(); | |
75 }); | |
76 }); | |
77 } | |
OLD | NEW |