Chromium Code Reviews| Index: pkg/barback/test/asset_graph/source_test.dart |
| diff --git a/pkg/barback/test/asset_graph/source_test.dart b/pkg/barback/test/asset_graph/source_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..86daf1f2fc9bf4a12df0ebd0e1248ee45c7d49d1 |
| --- /dev/null |
| +++ b/pkg/barback/test/asset_graph/source_test.dart |
| @@ -0,0 +1,109 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| +library barback.test.asset_graph.source_test; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:scheduled_test/scheduled_test.dart'; |
| + |
|
nweiz
2013/06/14 00:57:57
Unnecessary blank line.
Bob Nystrom
2013/06/17 23:35:05
Done.
|
| +import 'package:barback/barback.dart'; |
| +import 'package:barback/src/asset_graph.dart'; |
| + |
| +import '../utils.dart'; |
| + |
| +main() { |
| + initConfig(); |
| + test("gets a source asset", () { |
| + var provider = new MockProvider(["app|foo.txt"]); |
| + var graph = new AssetGraph(provider, []); |
| + graph.updateSources([AssetId.parse("app|foo.txt")]); |
| + |
| + expectAsset(graph, "app|foo.txt"); |
|
nweiz
2013/06/14 00:57:57
"expectAsset" is a confusing name. I have to look
Bob Nystrom
2013/06/17 23:35:05
"exists" is a bit confusing to me because that fee
nweiz
2013/06/18 23:14:45
I don't think it's particularly weird to have a ma
Bob Nystrom
2013/06/20 00:23:59
I've got some other test refactoring I want to do
|
| + }); |
| + |
| + test("doesn't get an unknown source", () { |
|
nweiz
2013/06/14 00:57:57
The term "source" is confusing. I think of package
Bob Nystrom
2013/06/17 23:35:05
I'm not crazy about it either. Maybe "raw" input?
nweiz
2013/06/18 23:14:45
Sure, another patch is fine.
|
| + var provider = new MockProvider(["app|foo.txt"]); |
| + var graph = new AssetGraph(provider, []); |
| + |
| + expectNoAsset(graph, "app|unknown.txt"); |
| + }); |
| + |
| + test("doesn't get an asset that isn't an updated source", () { |
| + var provider = new MockProvider(["app|foo.txt"]); |
| + var graph = new AssetGraph(provider, []); |
| + |
| + expectNoAsset(graph, "app|foo.txt"); |
|
nweiz
2013/06/14 00:57:57
Wait, why will this not exist? It's right there!
Bob Nystrom
2013/06/17 23:35:05
You have to specifically tell barback "this file e
nweiz
2013/06/18 23:14:45
So how does the user specify this? If I run "pub d
Bob Nystrom
2013/06/20 00:23:59
Pub deploy will automatically call updateSources()
nweiz
2013/06/20 23:06:08
It seems a little weird that the set of available
Bob Nystrom
2013/06/21 00:13:20
The code calling barback also is responsible for g
|
| + }); |
| + |
| + test("gets a source asset if not transformed", () { |
| + var provider = new MockProvider(["app|foo.txt"]); |
| + var graph = new AssetGraph(provider, [ |
| + [new RewriteTransformer("nottxt", "whatever")] |
| + ]); |
| + graph.updateSources([AssetId.parse("app|foo.txt")]); |
| + |
| + expectAsset(graph, "app|foo.txt"); |
| + }); |
| + |
| + test("doesn't get a removed source", () { |
| + var provider = new MockProvider(["app|foo.txt"]); |
| + var graph = new AssetGraph(provider, [[]]); |
| + |
| + schedule(() { |
| + graph.updateSources([AssetId.parse("app|foo.txt")]); |
|
nweiz
2013/06/14 00:57:57
Why is this [updateSources] scheduled, but the pre
Bob Nystrom
2013/06/17 23:35:05
No reason. Removed.
|
| + }); |
| + |
| + expectAsset(graph, "app|foo.txt"); |
| + |
| + schedule(() { |
| + graph.removeSources([AssetId.parse("app|foo.txt")]); |
| + }); |
| + |
| + expectNoAsset(graph, "app|foo.txt"); |
| + }); |
| + |
| + test("collapses redundant updates", () { |
| + var provider = new MockProvider({"app|foo.blub": "foo"}); |
| + var transformer = new RewriteTransformer("blub", "blab"); |
| + var graph = new AssetGraph(provider, [[transformer]]); |
| + |
| + schedule(() { |
| + // Make a bunch of synchronous update calls. |
| + graph.updateSources([AssetId.parse("app|foo.blub")]); |
| + graph.updateSources([AssetId.parse("app|foo.blub")]); |
| + graph.updateSources([AssetId.parse("app|foo.blub")]); |
| + graph.updateSources([AssetId.parse("app|foo.blub")]); |
| + }); |
| + |
| + expectAsset(graph, "app|foo.blab", "foo.blab"); |
| + |
| + schedule(() { |
| + expect(transformer.numRuns, equals(1)); |
| + }); |
| + }); |
| + |
| + test("a removal cancels out an update", () { |
| + var provider = new MockProvider(["app|foo.txt"]); |
| + var graph = new AssetGraph(provider, [[]]); |
| + |
| + schedule(() { |
| + graph.updateSources([AssetId.parse("app|foo.txt")]); |
| + graph.removeSources([AssetId.parse("app|foo.txt")]); |
| + }); |
| + |
| + expectNoAsset(graph, "app|foo.txt"); |
| + }); |
| + |
| + test("an update cancels out a removal", () { |
| + var provider = new MockProvider(["app|foo.txt"]); |
| + var graph = new AssetGraph(provider, [[]]); |
| + |
| + schedule(() { |
| + graph.removeSources([AssetId.parse("app|foo.txt")]); |
| + graph.updateSources([AssetId.parse("app|foo.txt")]); |
| + }); |
| + |
| + expectAsset(graph, "app|foo.txt"); |
| + }); |
| +} |
|
nweiz
2013/06/14 00:57:57
If this is where you're testing add/remove/update
Bob Nystrom
2013/06/17 23:35:05
There are some tests for this. Added a couple more
|