Chromium Code Reviews| 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 library barback.test.asset_graph.transform_test; | |
| 5 | |
| 6 import 'dart:async'; | |
| 7 | |
| 8 import 'package:barback/barback.dart'; | |
| 9 import 'package:barback/src/asset_graph.dart'; | |
| 10 import 'package:scheduled_test/scheduled_test.dart'; | |
| 11 | |
| 12 import '../utils.dart'; | |
| 13 | |
| 14 main() { | |
| 15 initConfig(); | |
| 16 test("gets a transformed asset with a different path", () { | |
| 17 var provider = new MockProvider({"app|foo.blub": "foo"}); | |
| 18 var graph = new AssetGraph(provider, [ | |
| 19 [new RewriteTransformer("blub", "blab")] | |
| 20 ]); | |
| 21 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 22 | |
| 23 expectAsset(graph, "app|foo.blab", "foo.blab"); | |
| 24 }); | |
| 25 | |
| 26 test("gets a transformed asset with the same path", () { | |
| 27 var provider = new MockProvider({"app|foo.blub": "blub"}); | |
| 28 var graph = new AssetGraph(provider, [ | |
| 29 [new RewriteTransformer("blub", "blub")] | |
| 30 ]); | |
| 31 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 32 | |
| 33 expectAsset(graph, "app|foo.blub", "blub.blub"); | |
| 34 }); | |
| 35 | |
| 36 test("doesn't find an output from a later phase", () { | |
| 37 var provider = new MockProvider({"app|foo.a": "a"}); | |
| 38 var graph = new AssetGraph(provider, [ | |
| 39 [new RewriteTransformer("b", "c")], | |
| 40 [new RewriteTransformer("a", "b")] | |
| 41 ]); | |
| 42 graph.updateSources([new AssetId.parse("app|foo.a")]); | |
| 43 | |
| 44 expectNoAsset(graph, "app|foo.c"); | |
| 45 }); | |
| 46 | |
| 47 test("doesn't find an output from the same phase", () { | |
| 48 var provider = new MockProvider({"app|foo.a": "a"}); | |
| 49 var graph = new AssetGraph(provider, [ | |
| 50 [ | |
| 51 new RewriteTransformer("a", "b"), | |
| 52 new RewriteTransformer("b", "c") | |
| 53 ] | |
| 54 ]); | |
| 55 graph.updateSources([new AssetId.parse("app|foo.a")]); | |
| 56 | |
| 57 expectAsset(graph, "app|foo.b", "a.b"); | |
| 58 expectNoAsset(graph, "app|foo.c"); | |
| 59 }); | |
| 60 | |
| 61 test("finds the latest output before the transformer's phase", () { | |
| 62 var provider = new MockProvider({"app|foo.blub": "foo"}); | |
| 63 var graph = new AssetGraph(provider, [ | |
| 64 [new RewriteTransformer("blub", "blub")], | |
| 65 [ | |
| 66 new RewriteTransformer("blub", "blub"), | |
| 67 new RewriteTransformer("blub", "done") | |
| 68 ], | |
| 69 [new RewriteTransformer("blub", "blub")] | |
| 70 ]); | |
| 71 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 72 | |
| 73 expectAsset(graph, "app|foo.done", "foo.blub.done"); | |
| 74 }); | |
| 75 | |
| 76 test("applies multiple transformations to an asset", () { | |
| 77 var provider = new MockProvider({"app|foo.a": "a"}); | |
| 78 var graph = new AssetGraph(provider, [ | |
| 79 [new RewriteTransformer("a", "b")], | |
| 80 [new RewriteTransformer("b", "c")], | |
| 81 [new RewriteTransformer("c", "d")], | |
| 82 [new RewriteTransformer("d", "e")], | |
| 83 [new RewriteTransformer("e", "f")], | |
| 84 [new RewriteTransformer("f", "g")], | |
| 85 [new RewriteTransformer("g", "h")], | |
| 86 [new RewriteTransformer("h", "i")], | |
| 87 [new RewriteTransformer("i", "j")], | |
| 88 [new RewriteTransformer("j", "k")], | |
| 89 ]); | |
| 90 graph.updateSources([new AssetId.parse("app|foo.a")]); | |
| 91 | |
| 92 expectAsset(graph, "app|foo.k", "a.b.c.d.e.f.g.h.i.j.k"); | |
| 93 }); | |
| 94 | |
| 95 test("only runs a transform once for all of its outputs", () { | |
| 96 var provider = new MockProvider(["app|foo.blub"]); | |
| 97 var transformer = new RewriteTransformer("blub", "a b c"); | |
| 98 var graph = new AssetGraph(provider, [[transformer]]); | |
| 99 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 100 | |
| 101 expectAsset(graph, "app|foo.a", ".a"); | |
| 102 expectAsset(graph, "app|foo.b", ".b"); | |
| 103 expectAsset(graph, "app|foo.c", ".c"); | |
| 104 schedule(() { | |
| 105 expect(transformer.numRuns, equals(1)); | |
| 106 }); | |
| 107 }); | |
| 108 | |
| 109 test("runs transforms in the same phase in parallel", () { | |
| 110 var provider = new MockProvider(["app|foo.txt"]); | |
| 111 var transformerA = new RewriteTransformer("txt", "a"); | |
| 112 var transformerB = new RewriteTransformer("txt", "b"); | |
| 113 var graph = new AssetGraph(provider, [[transformerA, transformerB]]); | |
| 114 | |
| 115 transformerA.wait(); | |
| 116 transformerB.wait(); | |
| 117 | |
| 118 schedule(() { | |
| 119 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 120 | |
| 121 // Wait for them both to start. | |
| 122 return Future.wait([transformerA.started, transformerB.started]); | |
| 123 }); | |
| 124 | |
| 125 schedule(() { | |
| 126 // They should both still be running. | |
| 127 expect(transformerA.isRunning, isTrue); | |
| 128 expect(transformerB.isRunning, isTrue); | |
| 129 | |
| 130 transformerA.complete(); | |
| 131 transformerB.complete(); | |
| 132 }); | |
| 133 | |
| 134 expectAsset(graph, "app|foo.a", ".a"); | |
| 135 expectAsset(graph, "app|foo.b", ".b"); | |
| 136 }); | |
| 137 | |
| 138 test("does not reapply transform when inputs are not modified", () { | |
| 139 var provider = new MockProvider({"app|foo.blub": "foo"}); | |
| 140 var transformer = new RewriteTransformer("blub", "blab"); | |
| 141 var graph = new AssetGraph(provider, [[transformer]]); | |
| 142 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 143 expectAsset(graph, "app|foo.blab", "foo.blab"); | |
| 144 expectAsset(graph, "app|foo.blab", "foo.blab"); | |
| 145 expectAsset(graph, "app|foo.blab", "foo.blab"); | |
| 146 | |
| 147 schedule(() { | |
| 148 expect(transformer.numRuns, equals(1)); | |
| 149 }); | |
| 150 }); | |
| 151 | |
| 152 test("reapplies a transform when its input is modified", () { | |
| 153 var provider = new MockProvider({"app|foo.blub": "foo"}); | |
| 154 var transformer = new RewriteTransformer("blub", "blab"); | |
| 155 var graph = new AssetGraph(provider, [[transformer]]); | |
| 156 | |
| 157 schedule(() { | |
| 158 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 159 }); | |
| 160 | |
| 161 expectAsset(graph, "app|foo.blab", "foo.blab"); | |
| 162 | |
| 163 schedule(() { | |
| 164 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 165 }); | |
| 166 | |
| 167 expectAsset(graph, "app|foo.blab", "foo.blab"); | |
| 168 | |
| 169 schedule(() { | |
| 170 graph.updateSources([new AssetId.parse("app|foo.blub")]); | |
| 171 }); | |
| 172 | |
| 173 expectAsset(graph, "app|foo.blab", "foo.blab"); | |
| 174 | |
| 175 schedule(() { | |
| 176 expect(transformer.numRuns, equals(3)); | |
| 177 }); | |
| 178 }); | |
| 179 | |
| 180 test("does not reapply transform when a removed input is modified", () { | |
| 181 var provider = new MockProvider({ | |
| 182 "app|a.txt": "a.inc,b.inc", | |
| 183 "app|a.inc": "a", | |
| 184 "app|b.inc": "b" | |
| 185 }); | |
| 186 | |
| 187 var transformer = new ManyToOneTransformer("txt"); | |
| 188 var graph = new AssetGraph(provider, [[transformer]]); | |
| 189 | |
| 190 graph.updateSources([ | |
| 191 new AssetId.parse("app|a.txt"), | |
| 192 new AssetId.parse("app|a.inc"), | |
| 193 new AssetId.parse("app|b.inc") | |
| 194 ]); | |
| 195 | |
| 196 expectAsset(graph, "app|a.out", "ab"); | |
| 197 | |
| 198 // Remove a non-primary input. | |
|
nweiz
2013/06/18 23:14:46
"Remove" is a little confusing here, since you're
Bob Nystrom
2013/06/20 00:23:59
Reworded.
| |
| 199 schedule(() { | |
| 200 provider.modifyAsset("app|a.txt", "a.inc"); | |
| 201 graph.updateSources([new AssetId.parse("app|a.txt")]); | |
| 202 }); | |
| 203 | |
| 204 // Process it again. | |
| 205 expectAsset(graph, "app|a.out", "a"); | |
| 206 | |
| 207 // Now touch the removed input. It should not trigger another build. | |
| 208 schedule(() { | |
| 209 graph.updateSources([new AssetId.parse("app|b.inc")]); | |
| 210 }); | |
| 211 | |
| 212 expectAsset(graph, "app|a.out", "a"); | |
| 213 | |
| 214 schedule(() { | |
| 215 expect(transformer.numRuns, equals(2)); | |
| 216 }); | |
| 217 }); | |
| 218 | |
| 219 test("allows a transform to generate multiple outputs", () { | |
| 220 var provider = new MockProvider({"app|foo.txt": "a.out,b.out"}); | |
| 221 var graph = new AssetGraph(provider, [ | |
| 222 [new OneToManyTransformer("txt")] | |
| 223 ]); | |
| 224 | |
| 225 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 226 | |
| 227 expectAsset(graph, "app|a.out", "spread txt"); | |
| 228 expectAsset(graph, "app|b.out", "spread txt"); | |
| 229 }); | |
| 230 | |
| 231 test("does not rebuild transforms that don't use modified source", () { | |
| 232 var provider = new MockProvider(["app|foo.a", "app|foo.b"]); | |
| 233 var a = new RewriteTransformer("a", "aa"); | |
| 234 var aa = new RewriteTransformer("aa", "aaa"); | |
| 235 var b = new RewriteTransformer("b", "bb"); | |
| 236 var bb = new RewriteTransformer("bb", "bbb"); | |
| 237 | |
| 238 var graph = new AssetGraph(provider, [ | |
| 239 [a, b], | |
| 240 [aa, bb], | |
| 241 ]); | |
| 242 | |
| 243 graph.updateSources([new AssetId.parse("app|foo.a")]); | |
| 244 graph.updateSources([new AssetId.parse("app|foo.b")]); | |
| 245 | |
| 246 expectAsset(graph, "app|foo.aaa", ".aa.aaa"); | |
| 247 expectAsset(graph, "app|foo.bbb", ".bb.bbb"); | |
| 248 | |
| 249 schedule(() { | |
| 250 graph.updateSources([new AssetId.parse("app|foo.a")]); | |
| 251 }); | |
| 252 | |
| 253 expectAsset(graph, "app|foo.aaa", ".aa.aaa"); | |
| 254 expectAsset(graph, "app|foo.bbb", ".bb.bbb"); | |
| 255 | |
| 256 schedule(() { | |
| 257 expect(aa.numRuns, equals(2)); | |
| 258 expect(bb.numRuns, equals(1)); | |
| 259 }); | |
| 260 }); | |
| 261 | |
| 262 test("doesn't get an output from a transform whose primary is removed", () { | |
|
nweiz
2013/06/18 23:14:46
"primary" -> "primary input"
Bob Nystrom
2013/06/20 00:23:59
Done.
| |
| 263 var provider = new MockProvider(["app|foo.txt"]); | |
| 264 var graph = new AssetGraph(provider, [ | |
| 265 [new RewriteTransformer("txt", "out")] | |
| 266 ]); | |
| 267 | |
| 268 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 269 | |
| 270 expectAsset(graph, "app|foo.out", ".out"); | |
| 271 | |
| 272 schedule(() { | |
| 273 graph.removeSources([new AssetId.parse("app|foo.txt")]); | |
| 274 }); | |
| 275 | |
| 276 expectNoAsset(graph, "app|foo.out"); | |
| 277 }); | |
| 278 | |
| 279 test("reapplies a transform when a non-primary input changes", () { | |
| 280 var provider = new MockProvider({ | |
| 281 "app|a.txt": "a.inc", | |
| 282 "app|a.inc": "a" | |
| 283 }); | |
| 284 | |
| 285 var graph = new AssetGraph(provider, [ | |
| 286 [new ManyToOneTransformer("txt")] | |
| 287 ]); | |
| 288 | |
| 289 graph.updateSources([ | |
| 290 new AssetId.parse("app|a.txt"), | |
| 291 new AssetId.parse("app|a.inc") | |
| 292 ]); | |
| 293 | |
| 294 expectAsset(graph, "app|a.out", "a"); | |
| 295 | |
| 296 schedule(() { | |
| 297 provider.modifyAsset("app|a.inc", "after"); | |
| 298 graph.updateSources([new AssetId.parse("app|a.inc")]); | |
| 299 }); | |
| 300 | |
| 301 expectAsset(graph, "app|a.out", "after"); | |
| 302 }); | |
| 303 | |
| 304 test("restarts processing if a change occurs during processing", () { | |
| 305 var provider = new MockProvider(["app|foo.txt"]); | |
| 306 var transformer = new RewriteTransformer("txt", "out"); | |
| 307 var graph = new AssetGraph(provider, [[transformer]]); | |
| 308 | |
| 309 transformer.wait(); | |
| 310 | |
| 311 schedule(() { | |
| 312 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 313 | |
| 314 // Wait for the transform to start. | |
| 315 return transformer.started; | |
| 316 }); | |
| 317 | |
| 318 schedule(() { | |
| 319 // Now update the graph during it. | |
| 320 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 321 }); | |
| 322 | |
| 323 schedule(() { | |
| 324 transformer.complete(); | |
| 325 }); | |
| 326 | |
| 327 expectAsset(graph, "app|foo.out", ".out"); | |
| 328 | |
| 329 schedule(() { | |
| 330 expect(transformer.numRuns, equals(2)); | |
| 331 }); | |
| 332 }); | |
| 333 | |
| 334 test("handles an output moving from one transformer to another", () { | |
| 335 // In the first run, "shared.out" is created by the "a.a" transformer. | |
| 336 var provider = new MockProvider({ | |
| 337 "app|a.a": "a.out,shared.out", | |
| 338 "app|b.b": "b.out" | |
| 339 }); | |
| 340 | |
| 341 var graph = new AssetGraph(provider, [ | |
| 342 [new OneToManyTransformer("a"), new OneToManyTransformer("b")] | |
| 343 ]); | |
| 344 | |
| 345 graph.updateSources([ | |
| 346 new AssetId.parse("app|a.a"), | |
| 347 new AssetId.parse("app|b.b") | |
| 348 ]); | |
| 349 | |
| 350 expectAsset(graph, "app|a.out", "spread a"); | |
| 351 expectAsset(graph, "app|b.out", "spread b"); | |
| 352 expectAsset(graph, "app|shared.out", "spread a"); | |
| 353 | |
| 354 // Now switch their contents so that "shared.out" will be output by "b.b"'s | |
| 355 // transformer. | |
| 356 schedule(() { | |
| 357 provider.modifyAsset("app|a.a", "a.out"); | |
| 358 provider.modifyAsset("app|b.b", "b.out,shared.out"); | |
| 359 graph.updateSources([ | |
| 360 new AssetId.parse("app|a.a"), | |
| 361 new AssetId.parse("app|b.b") | |
| 362 ]); | |
| 363 }); | |
| 364 | |
| 365 expectAsset(graph, "app|a.out", "spread a"); | |
| 366 expectAsset(graph, "app|b.out", "spread b"); | |
| 367 expectAsset(graph, "app|shared.out", "spread b"); | |
| 368 }); | |
| 369 | |
| 370 test("restarts before finishing later phases when a change occurs", () { | |
| 371 var provider = new MockProvider(["app|foo.txt", "app|bar.txt"]); | |
| 372 | |
| 373 var txtToInt = new RewriteTransformer("txt", "int"); | |
| 374 var intToOut = new RewriteTransformer("int", "out"); | |
| 375 var graph = new AssetGraph(provider, [[txtToInt], [intToOut]]); | |
| 376 | |
| 377 txtToInt.wait(); | |
| 378 | |
| 379 schedule(() { | |
| 380 graph.updateSources([new AssetId.parse("app|foo.txt")]); | |
| 381 | |
| 382 // Wait for the first transform to start. | |
| 383 return txtToInt.started; | |
| 384 }); | |
| 385 | |
| 386 schedule(() { | |
| 387 // Now update the graph during it. | |
| 388 graph.updateSources([new AssetId.parse("app|bar.txt")]); | |
| 389 }); | |
| 390 | |
| 391 schedule(() { | |
| 392 txtToInt.complete(); | |
| 393 }); | |
| 394 | |
| 395 expectAsset(graph, "app|foo.out", ".int.out"); | |
| 396 expectAsset(graph, "app|bar.out", ".int.out"); | |
| 397 | |
| 398 schedule(() { | |
| 399 // Should only have run each transform once for each primary. | |
| 400 expect(txtToInt.numRuns, equals(2)); | |
| 401 expect(intToOut.numRuns, equals(2)); | |
| 402 }); | |
| 403 }); | |
| 404 } | |
| OLD | NEW |