OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS 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 barback.test.barback_test; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'package:barback/barback.dart'; | |
10 import 'package:scheduled_test/scheduled_test.dart'; | |
11 | |
12 import '../utils.dart'; | |
13 | |
14 main() { | |
15 initConfig(); | |
16 | |
17 test("gets all source assets", () { | |
18 initGraph(["app|a.txt", "app|b.txt", "app|c.txt"]); | |
19 updateSources(["app|a.txt", "app|b.txt", "app|c.txt"]); | |
20 expectAllAssets(["app|a.txt", "app|b.txt", "app|c.txt"]); | |
21 buildShouldSucceed(); | |
22 }); | |
23 | |
24 test("includes transformed outputs", () { | |
25 initGraph(["app|a.txt", "app|foo.blub"], {"app": [ | |
26 [new RewriteTransformer("blub", "blab")] | |
27 ]}); | |
28 updateSources(["app|a.txt", "app|foo.blub"]); | |
29 expectAllAssets(["app|a.txt", "app|foo.blub", "app|foo.blab"]); | |
30 buildShouldSucceed(); | |
31 }); | |
32 | |
33 test("includes overwritten outputs", () { | |
34 initGraph(["app|a.txt", "app|foo.blub"], {"app": [ | |
35 [new RewriteTransformer("blub", "blub")] | |
36 ]}); | |
37 updateSources(["app|a.txt", "app|foo.blub"]); | |
38 expectAllAssets({ | |
39 "app|a.txt": "a", | |
40 "app|foo.blub": "foo.blub" | |
41 }); | |
42 buildShouldSucceed(); | |
43 }); | |
44 | |
45 test("completes to an error if two transformers output the same file", () { | |
46 initGraph(["app|foo.a"], {"app": [ | |
47 [ | |
48 new RewriteTransformer("a", "b"), | |
49 new RewriteTransformer("a", "b") | |
50 ] | |
51 ]}); | |
52 updateSources(["app|foo.a"]); | |
53 expectAllAssetsShouldFail(isAssetCollisionException("app|foo.b")); | |
54 }); | |
55 | |
56 test("completes to an error if a transformer fails", () { | |
57 initGraph(["app|foo.txt"], {"app": [ | |
58 [new BadTransformer(["app|foo.out"])] | |
59 ]}); | |
60 | |
61 updateSources(["app|foo.txt"]); | |
62 expectAllAssetsShouldFail(isTransformerException( | |
63 equals(BadTransformer.ERROR))); | |
64 }); | |
65 | |
66 test("completes to an aggregate error if there are multiple errors", () { | |
67 initGraph(["app|foo.txt"], {"app": [ | |
68 [ | |
69 new BadTransformer(["app|foo.out"]), | |
70 new BadTransformer(["app|foo.out2"]) | |
71 ] | |
72 ]}); | |
73 | |
74 updateSources(["app|foo.txt"]); | |
75 expectAllAssetsShouldFail(isAggregateException([ | |
76 isTransformerException(equals(BadTransformer.ERROR)), | |
77 isTransformerException(equals(BadTransformer.ERROR)) | |
78 ])); | |
79 }); | |
80 | |
81 // Regression test. | |
82 test("getAllAssets() is called synchronously after after initializing " | |
83 "barback", () { | |
84 var provider = new MockProvider({ | |
85 "app|a.txt": "a", | |
86 "app|b.txt": "b", | |
87 "app|c.txt": "c" | |
88 }); | |
89 var barback = new Barback(provider); | |
90 barback.updateSources([ | |
91 new AssetId.parse("app|a.txt"), | |
92 new AssetId.parse("app|b.txt"), | |
93 new AssetId.parse("app|c.txt") | |
94 ]); | |
95 | |
96 expect(barback.getAllAssets().then((assets) { | |
97 return Future.wait(assets.map((asset) => asset.readAsString())); | |
98 }), completion(unorderedEquals(["a", "b", "c"]))); | |
99 }); | |
100 } | |
OLD | NEW |