| 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.package_graph.source_test; | 5 library barback.test.package_graph.source_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:barback/src/utils.dart'; | 10 import 'package:barback/src/utils.dart'; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 buildShouldSucceed(); | 54 buildShouldSucceed(); |
| 55 }); | 55 }); |
| 56 | 56 |
| 57 test("doesn't get a removed source", () { | 57 test("doesn't get a removed source", () { |
| 58 initGraph(["app|foo.txt"]); | 58 initGraph(["app|foo.txt"]); |
| 59 | 59 |
| 60 updateSources(["app|foo.txt"]); | 60 updateSources(["app|foo.txt"]); |
| 61 expectAsset("app|foo.txt"); | 61 expectAsset("app|foo.txt"); |
| 62 buildShouldSucceed(); | 62 buildShouldSucceed(); |
| 63 | 63 |
| 64 schedule(() { | 64 removeSources(["app|foo.txt"]); |
| 65 removeSources(["app|foo.txt"]); | |
| 66 }); | |
| 67 | |
| 68 expectNoAsset("app|foo.txt"); | 65 expectNoAsset("app|foo.txt"); |
| 69 buildShouldSucceed(); | 66 buildShouldSucceed(); |
| 70 }); | 67 }); |
| 71 | 68 |
| 72 test("collapses redundant updates", () { | 69 test("collapses redundant updates", () { |
| 73 var transformer = new RewriteTransformer("blub", "blab"); | 70 var transformer = new RewriteTransformer("blub", "blab"); |
| 74 initGraph(["app|foo.blub"], {"app": [[transformer]]}); | 71 initGraph(["app|foo.blub"], {"app": [[transformer]]}); |
| 75 | 72 |
| 76 schedule(() { | 73 schedule(() { |
| 77 // Make a bunch of synchronous update calls. | 74 // Make a bunch of synchronous update calls. |
| 78 updateSources(["app|foo.blub"]); | 75 updateSourcesSync(["app|foo.blub"]); |
| 79 updateSources(["app|foo.blub"]); | 76 updateSourcesSync(["app|foo.blub"]); |
| 80 updateSources(["app|foo.blub"]); | 77 updateSourcesSync(["app|foo.blub"]); |
| 81 updateSources(["app|foo.blub"]); | 78 updateSourcesSync(["app|foo.blub"]); |
| 82 }); | 79 }); |
| 83 | 80 |
| 84 expectAsset("app|foo.blab", "foo.blab"); | 81 expectAsset("app|foo.blab", "foo.blab"); |
| 85 buildShouldSucceed(); | 82 buildShouldSucceed(); |
| 86 | 83 |
| 87 schedule(() { | 84 expect(transformer.numRuns, completion(equals(1))); |
| 88 expect(transformer.numRuns, equals(1)); | |
| 89 }); | |
| 90 }); | 85 }); |
| 91 | 86 |
| 92 test("a removal cancels out an update", () { | 87 test("a removal cancels out an update", () { |
| 93 initGraph(["app|foo.txt"]); | 88 initGraph(["app|foo.txt"]); |
| 94 | 89 |
| 95 schedule(() { | 90 schedule(() { |
| 96 updateSources(["app|foo.txt"]); | 91 updateSourcesSync(["app|foo.txt"]); |
| 97 removeSources(["app|foo.txt"]); | 92 removeSourcesSync(["app|foo.txt"]); |
| 98 }); | 93 }); |
| 99 | 94 |
| 100 expectNoAsset("app|foo.txt"); | 95 expectNoAsset("app|foo.txt"); |
| 101 buildShouldSucceed(); | 96 buildShouldSucceed(); |
| 102 }); | 97 }); |
| 103 | 98 |
| 104 test("an update cancels out a removal", () { | 99 test("an update cancels out a removal", () { |
| 105 initGraph(["app|foo.txt"]); | 100 initGraph(["app|foo.txt"]); |
| 106 | 101 |
| 107 schedule(() { | 102 schedule(() { |
| 108 removeSources(["app|foo.txt"]); | 103 removeSourcesSync(["app|foo.txt"]); |
| 109 updateSources(["app|foo.txt"]); | 104 updateSourcesSync(["app|foo.txt"]); |
| 110 }); | 105 }); |
| 111 | 106 |
| 112 expectAsset("app|foo.txt"); | 107 expectAsset("app|foo.txt"); |
| 113 buildShouldSucceed(); | 108 buildShouldSucceed(); |
| 114 }); | 109 }); |
| 115 | 110 |
| 116 test("reloads an asset that's updated while loading", () { | 111 test("reloads an asset that's updated while loading", () { |
| 117 initGraph({"app|foo.txt": "foo"}); | 112 initGraph({"app|foo.txt": "foo"}); |
| 118 | 113 |
| 119 pauseProvider(); | 114 pauseProvider(); |
| 120 schedule(() { | 115 // The mock provider synchronously loads the value of the assets, so this |
| 121 // The mock provider synchronously loads the value of the assets, so this | 116 // will kick off two loads with different values. The second one should |
| 122 // will kick off two loads with different values. The second one should | 117 // win. |
| 123 // win. | 118 updateSources(["app|foo.txt"]); |
| 124 updateSources(["app|foo.txt"]); | 119 modifyAsset("app|foo.txt", "bar"); |
| 125 modifyAsset("app|foo.txt", "bar"); | 120 updateSources(["app|foo.txt"]); |
| 126 updateSources(["app|foo.txt"]); | |
| 127 }); | |
| 128 | 121 |
| 129 resumeProvider(); | 122 resumeProvider(); |
| 130 expectAsset("app|foo.txt", "bar"); | 123 expectAsset("app|foo.txt", "bar"); |
| 131 buildShouldSucceed(); | 124 buildShouldSucceed(); |
| 132 }); | 125 }); |
| 133 | 126 |
| 134 test("restarts a build if a source is updated while sources are loading", () { | 127 test("restarts a build if a source is updated while sources are loading", () { |
| 135 var transformer = new RewriteTransformer("txt", "out"); | 128 var transformer = new RewriteTransformer("txt", "out"); |
| 136 initGraph(["app|foo.txt", "app|other.bar"], {"app": [[transformer]]}); | 129 initGraph(["app|foo.txt", "app|other.bar"], {"app": [[transformer]]}); |
| 137 | 130 |
| 138 // Run the whole graph so all nodes are clean. | 131 // Run the whole graph so all nodes are clean. |
| 139 updateSources(["app|foo.txt", "app|other.bar"]); | 132 updateSources(["app|foo.txt", "app|other.bar"]); |
| 140 expectAsset("app|foo.out", "foo.out"); | 133 expectAsset("app|foo.out", "foo.out"); |
| 141 expectAsset("app|other.bar"); | 134 expectAsset("app|other.bar"); |
| 142 | 135 |
| 143 buildShouldSucceed(); | 136 buildShouldSucceed(); |
| 144 | 137 |
| 145 // Make the provider slow to load a source. | 138 // Make the provider slow to load a source. |
| 146 pauseProvider(); | 139 pauseProvider(); |
| 147 | 140 |
| 148 schedule(() { | 141 // Update an asset that doesn't trigger any transformers. |
| 149 // Update an asset that doesn't trigger any transformers. | 142 updateSources(["app|other.bar"]); |
| 150 updateSources(["app|other.bar"]); | |
| 151 }); | |
| 152 | 143 |
| 153 schedule(() { | 144 // Now update an asset that does trigger a transformer. |
| 154 // Now update an asset that does trigger a transformer. | 145 updateSources(["app|foo.txt"]); |
| 155 updateSources(["app|foo.txt"]); | |
| 156 }); | |
| 157 | 146 |
| 158 resumeProvider(); | 147 resumeProvider(); |
| 159 | 148 |
| 160 buildShouldSucceed(); | 149 buildShouldSucceed(); |
| 161 waitForBuild(); | |
| 162 | 150 |
| 163 schedule(() { | 151 expect(transformer.numRuns, completion(equals(2))); |
| 164 expect(transformer.numRuns, equals(2)); | |
| 165 }); | |
| 166 }); | 152 }); |
| 167 } | 153 } |
| OLD | NEW |