Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1284)

Unified Diff: test/build/import_crawler_test.dart

Issue 978453003: add option to ImportCrawler to start from an already parsed document (Closed) Base URL: git@github.com:dart-lang/web-components.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/build/import_crawler_test.dart
diff --git a/test/build/import_crawler_test.dart b/test/build/import_crawler_test.dart
index 776ee1cec54a1084218aaaaff3f50d34a7f1977b..c140c09a9fb1c61908007cec295236f937be7126 100644
--- a/test/build/import_crawler_test.dart
+++ b/test/build/import_crawler_test.dart
@@ -3,24 +3,42 @@
// BSD-style license that can be found in the LICENSE file.
library web_components.test.build.import_crawler_test;
+import 'dart:async';
import 'package:barback/barback.dart';
import 'package:code_transformers/tests.dart';
import 'package:code_transformers/messages/build_logger.dart';
+import 'package:html5lib/dom.dart' show Document;
+import 'package:web_components/build/common.dart';
import 'package:web_components/build/import_crawler.dart';
import 'package:unittest/compact_vm_config.dart';
class _TestTransformer extends Transformer {
final String _entryPoint;
Map<AssetId, ImportData> documents;
+ final bool _preParseDocument;
- _TestTransformer(this._entryPoint);
+ _TestTransformer(this._entryPoint, [this._preParseDocument = false]);
isPrimary(AssetId id) => id.path == _entryPoint;
apply(Transform transform) {
var primaryInput = transform.primaryInput;
var logger = new BuildLogger(transform, primaryId: primaryInput.id);
- var crawler = new ImportCrawler(transform, primaryInput.id, logger);
+ if (_preParseDocument) {
+ return primaryInput.readAsString().then((html) {
+ var document = parseHtml(html, primaryInput.id.path);
+ return crawlDocument(transform, logger, document);
+ });
+ } else {
+ return crawlDocument(transform, logger);
+ }
+ }
+
+ Future crawlDocument(
+ Transform transform, BuildLogger logger, [Document document]) {
+ var primaryInput = transform.primaryInput;
+ var crawler = new ImportCrawler(
+ transform, primaryInput.id, logger, primaryDocument: document);
return crawler.crawlImports().then((docs) {
documents = docs;
transform.addOutput(new Asset.fromString(
@@ -31,8 +49,13 @@ class _TestTransformer extends Transformer {
main() {
useCompactVMConfiguration();
+ runTests([[new _TestTransformer('web/index.html')]]);
+ // Test with a preparsed original document as well.
+ runTests([[new _TestTransformer('web/index.html', true)]]);
+}
- testPhases('basic', [[new _TestTransformer('web/index.html')]], {
+runTests(List<List<Transformer>> phases) {
+ testPhases('basic', phases, {
'a|web/index.html': '''
<link rel="import" href="foo.html">
<link rel="import" href="packages/a/foo.html">
@@ -53,7 +76,7 @@ main() {
''',
}, [], StringFormatter.noNewlinesOrSurroundingWhitespace);
- testPhases('cycle', [[new _TestTransformer('web/index.html')]], {
+ testPhases('cycle', phases, {
'a|web/index.html': '''
<link rel="import" href="packages/a/foo.html">
<div>a|web/index.html</div>
@@ -70,7 +93,7 @@ main() {
''',
}, [], StringFormatter.noNewlinesOrSurroundingWhitespace);
- testPhases('deep imports', [[new _TestTransformer('web/index.html')]], {
+ testPhases('deep imports', phases, {
'a|web/index.html': '''
<link rel="import" href="packages/a/foo.html">
<div>a|web/index.html</div>
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698