OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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.package_graph.declaring_transformer_test; |
| 6 |
| 7 import 'package:barback/barback.dart'; |
| 8 import 'package:barback/src/utils.dart'; |
| 9 import 'package:scheduled_test/scheduled_test.dart'; |
| 10 |
| 11 import '../utils.dart'; |
| 12 |
| 13 main() { |
| 14 initConfig(); |
| 15 |
| 16 test("gets a declared output with a different path", () { |
| 17 initGraph(["app|foo.blub"], {"app": [ |
| 18 [new DeclaringRewriteTransformer("blub", "blab")] |
| 19 ]}); |
| 20 updateSources(["app|foo.blub"]); |
| 21 expectAsset("app|foo.blab", "foo.blab"); |
| 22 buildShouldSucceed(); |
| 23 }); |
| 24 |
| 25 test("gets a declared output with the same path", () { |
| 26 initGraph(["app|foo.blub"], {"app": [ |
| 27 [new DeclaringRewriteTransformer("blub", "blub")] |
| 28 ]}); |
| 29 updateSources(["app|foo.blub"]); |
| 30 expectAsset("app|foo.blub", "foo.blub"); |
| 31 buildShouldSucceed(); |
| 32 }); |
| 33 |
| 34 test("gets a passed-through asset", () { |
| 35 initGraph(["app|foo.blub"], {"app": [ |
| 36 [new DeclaringRewriteTransformer("blub", "blab")] |
| 37 ]}); |
| 38 updateSources(["app|foo.blub"]); |
| 39 expectAsset("app|foo.blub", "foo"); |
| 40 buildShouldSucceed(); |
| 41 }); |
| 42 |
| 43 test("doesn't get a consumed asset", () { |
| 44 initGraph(["app|foo.blub"], {"app": [ |
| 45 [new DeclaringRewriteTransformer("blub", "blab")..consumePrimary = true] |
| 46 ]}); |
| 47 updateSources(["app|foo.blub"]); |
| 48 expectNoAsset("app|foo.blub"); |
| 49 buildShouldSucceed(); |
| 50 }); |
| 51 |
| 52 test("gets a passed-through asset before apply is finished", () { |
| 53 var transformer = new DeclaringRewriteTransformer("blub", "blab"); |
| 54 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 55 |
| 56 transformer.pauseApply(); |
| 57 updateSources(["app|foo.blub"]); |
| 58 expectAsset("app|foo.blub", "foo"); |
| 59 |
| 60 transformer.resumeApply(); |
| 61 buildShouldSucceed(); |
| 62 }); |
| 63 |
| 64 test("fails to get a consumed asset before apply is finished", () { |
| 65 var transformer = new DeclaringRewriteTransformer("blub", "blab") |
| 66 ..consumePrimary = true; |
| 67 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 68 |
| 69 transformer.pauseApply(); |
| 70 updateSources(["app|foo.blub"]); |
| 71 expectNoAsset("app|foo.blub"); |
| 72 |
| 73 transformer.resumeApply(); |
| 74 buildShouldSucceed(); |
| 75 }); |
| 76 |
| 77 test("waits until apply is finished to get an overwritten asset", () { |
| 78 var transformer = new DeclaringRewriteTransformer("blub", "blub"); |
| 79 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 80 |
| 81 transformer.pauseApply(); |
| 82 updateSources(["app|foo.blub"]); |
| 83 expectAssetDoesNotComplete("app|foo.blub"); |
| 84 |
| 85 transformer.resumeApply(); |
| 86 expectAsset("app|foo.blub", "foo.blub"); |
| 87 buildShouldSucceed(); |
| 88 }); |
| 89 |
| 90 group("with an error in declareOutputs", () { |
| 91 test("still runs apply", () { |
| 92 initGraph(["app|foo.txt"], {"app": [[ |
| 93 new DeclaringBadTransformer("app|out.txt", |
| 94 declareError: true, applyError: false) |
| 95 ]]}); |
| 96 |
| 97 updateSources(["app|foo.txt"]); |
| 98 expectAsset("app|out.txt", "bad out"); |
| 99 expectAsset("app|foo.txt", "foo"); |
| 100 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 101 }); |
| 102 |
| 103 test("waits for apply to complete before passing through the input even if " |
| 104 "consumePrimary was called", () { |
| 105 var transformer = new DeclaringBadTransformer("app|out.txt", |
| 106 declareError: true, applyError: false)..consumePrimary = true; |
| 107 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 108 |
| 109 transformer.pauseApply(); |
| 110 updateSources(["app|foo.txt"]); |
| 111 expectAssetDoesNotComplete("app|out.txt"); |
| 112 expectAssetDoesNotComplete("app|foo.txt"); |
| 113 |
| 114 transformer.resumeApply(); |
| 115 expectAsset("app|out.txt", "bad out"); |
| 116 expectNoAsset("app|foo.txt"); |
| 117 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 118 }); |
| 119 }); |
| 120 |
| 121 test("with an error in apply still passes through the input", () { |
| 122 initGraph(["app|foo.txt"], {"app": [[ |
| 123 new DeclaringBadTransformer("app|out.txt", |
| 124 declareError: false, applyError: true) |
| 125 ]]}); |
| 126 |
| 127 updateSources(["app|foo.txt"]); |
| 128 expectNoAsset("app|out.txt"); |
| 129 expectAsset("app|foo.txt", "foo"); |
| 130 buildShouldFail([isTransformerException(BadTransformer.ERROR)]); |
| 131 }); |
| 132 |
| 133 test("can emit outputs it didn't declare", () { |
| 134 initGraph(["app|foo.txt"], {"app": [ |
| 135 [new DeclareAssetsTransformer([], ["app|out.txt"])] |
| 136 ]}); |
| 137 |
| 138 updateSources(["app|foo.txt"]); |
| 139 // There's probably going to be some time when "out.txt" is unavailable, |
| 140 // since it was undeclared. |
| 141 schedule(pumpEventQueue); |
| 142 expectAsset("app|out.txt", "app|out.txt"); |
| 143 buildShouldSucceed(); |
| 144 }); |
| 145 |
| 146 test("can overwrite the primary input even if it declared that it wouldn't", |
| 147 () { |
| 148 var transformer = new DeclareAssetsTransformer([], ["app|foo.txt"]); |
| 149 initGraph(["app|foo.txt"], {"app": [[transformer]]}); |
| 150 |
| 151 transformer.pauseApply(); |
| 152 updateSources(["app|foo.txt"]); |
| 153 expectAsset("app|foo.txt", "foo"); |
| 154 |
| 155 transformer.resumeApply(); |
| 156 schedule(pumpEventQueue); |
| 157 expectAsset("app|foo.txt", "app|foo.txt"); |
| 158 buildShouldSucceed(); |
| 159 }); |
| 160 |
| 161 test("can declare outputs it doesn't emit", () { |
| 162 initGraph(["app|foo.txt"], {"app": [ |
| 163 [new DeclareAssetsTransformer(["app|out.txt"], [])] |
| 164 ]}); |
| 165 |
| 166 updateSources(["app|foo.txt"]); |
| 167 expectNoAsset("app|out.txt"); |
| 168 buildShouldSucceed(); |
| 169 }); |
| 170 } |
OLD | NEW |