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 'dart:convert'; | |
8 | |
9 import 'package:scheduled_test/scheduled_stream.dart'; | |
10 | |
11 import '../descriptor.dart' as d; | |
12 import '../test_pub.dart'; | |
13 import '../serve/utils.dart'; | |
14 | |
15 final transformer = """ | |
16 import 'dart:async'; | |
17 import 'dart:convert'; | |
18 | |
19 import 'package:barback/barback.dart'; | |
20 | |
21 class GetInputTransformer extends Transformer { | |
22 GetInputTransformer.asPlugin(); | |
23 | |
24 String get allowedExtensions => '.txt'; | |
25 | |
26 Future apply(Transform transform) { | |
27 return transform.readInputAsString(new AssetId('myapp', 'nonexistent')) | |
28 .catchError((error) { | |
29 if (error is! AssetNotFoundException) throw error; | |
30 transform.addOutput(new Asset.fromString(transform.primaryInput.id, | |
31 JSON.encode({ | |
32 'package': error.id.package, | |
33 'path': error.id.path | |
34 }))); | |
35 }); | |
36 } | |
37 } | |
38 """; | |
39 | |
40 main() { | |
41 initConfig(); | |
42 withBarbackVersions("any", () { | |
43 integration("AssetNotFoundExceptions are detectable", () { | |
44 d.dir(appPath, [d.pubspec({ | |
45 "name": "myapp", | |
46 "transformers": ["myapp/src/transformer"] | |
47 }), | |
48 d.dir("lib", [d.dir("src", [d.file("transformer.dart", transformer)]
)]), | |
49 d.dir("web", [d.file("foo.txt", "foo")])]).create(); | |
50 | |
51 createLockFile('myapp', pkg: ['barback']); | |
52 | |
53 var server = pubServe(); | |
54 requestShouldSucceed("foo.txt", JSON.encode({ | |
55 "package": "myapp", | |
56 "path": "nonexistent" | |
57 })); | |
58 endPubServe(); | |
59 | |
60 // Since the AssetNotFoundException was caught and handled, the server | |
61 // shouldn't print any error information for it. | |
62 server.stderr.expect(isDone); | |
63 }); | |
64 }); | |
65 } | |
OLD | NEW |