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