OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 @TestOn('vm') |
4 library web_components.test.build.import_crawler_test; | 5 library web_components.test.build.import_crawler_test; |
5 | 6 |
6 import 'dart:async'; | 7 import 'dart:async'; |
7 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
8 import 'package:code_transformers/tests.dart'; | 9 import 'package:transformer_test/utils.dart'; |
9 import 'package:code_transformers/messages/build_logger.dart'; | 10 import 'package:code_transformers/messages/build_logger.dart'; |
10 import 'package:html/dom.dart' show Document; | 11 import 'package:html/dom.dart' show Document; |
11 import 'package:web_components/build/common.dart'; | 12 import 'package:web_components/build/common.dart'; |
12 import 'package:web_components/build/import_crawler.dart'; | 13 import 'package:web_components/build/import_crawler.dart'; |
13 import 'package:unittest/compact_vm_config.dart'; | 14 import 'package:test/test.dart'; |
14 | 15 |
15 class _TestTransformer extends Transformer { | 16 class _TestTransformer extends Transformer { |
16 final String _entryPoint; | 17 final String _entryPoint; |
17 Map<AssetId, ImportData> documents; | 18 Map<AssetId, ImportData> documents; |
18 final bool _preParseDocument; | 19 final bool _preParseDocument; |
19 | 20 |
20 _TestTransformer(this._entryPoint, [this._preParseDocument = false]); | 21 _TestTransformer(this._entryPoint, [this._preParseDocument = false]); |
21 | 22 |
22 isPrimary(AssetId id) => id.path == _entryPoint; | 23 isPrimary(AssetId id) => id.path == _entryPoint; |
23 | 24 |
(...skipping 17 matching lines...) Expand all Loading... |
41 primaryDocument: document); | 42 primaryDocument: document); |
42 return crawler.crawlImports().then((docs) { | 43 return crawler.crawlImports().then((docs) { |
43 documents = docs; | 44 documents = docs; |
44 transform.addOutput(new Asset.fromString( | 45 transform.addOutput(new Asset.fromString( |
45 new AssetId('a', 'web/result.txt'), '${documents.keys}')); | 46 new AssetId('a', 'web/result.txt'), '${documents.keys}')); |
46 }); | 47 }); |
47 } | 48 } |
48 } | 49 } |
49 | 50 |
50 main() { | 51 main() { |
51 useCompactVMConfiguration(); | 52 runTests([ |
52 runTests([[new _TestTransformer('web/index.html')]]); | 53 [new _TestTransformer('web/index.html')] |
| 54 ]); |
53 // Test with a preparsed original document as well. | 55 // Test with a preparsed original document as well. |
54 runTests([[new _TestTransformer('web/index.html', true)]]); | 56 runTests([ |
| 57 [new _TestTransformer('web/index.html', true)] |
| 58 ]); |
55 } | 59 } |
56 | 60 |
57 runTests(List<List<Transformer>> phases) { | 61 runTests(List<List<Transformer>> phases) { |
58 testPhases('basic', phases, { | 62 testPhases( |
59 'a|web/index.html': ''' | 63 'basic', |
| 64 phases, |
| 65 { |
| 66 'a|web/index.html': ''' |
60 <link rel="import" href="foo.html"> | 67 <link rel="import" href="foo.html"> |
61 <link rel="import" href="packages/a/foo.html"> | 68 <link rel="import" href="packages/a/foo.html"> |
62 <link rel="import" href="packages/b/foo.html"> | 69 <link rel="import" href="packages/b/foo.html"> |
63 <link rel="import" href="packages/b/foo/bar.html"> | 70 <link rel="import" href="packages/b/foo/bar.html"> |
64 <div>a|web/index.html</div> | 71 <div>a|web/index.html</div> |
65 ''', | 72 ''', |
66 'a|web/foo.html': '<div>a|web/foo.html</div>', | 73 'a|web/foo.html': '<div>a|web/foo.html</div>', |
67 'a|lib/foo.html': '<div>a|lib/foo.html</div>', | 74 'a|lib/foo.html': '<div>a|lib/foo.html</div>', |
68 'b|lib/foo.html': ''' | 75 'b|lib/foo.html': ''' |
69 <link rel="import" href="foo/bar.html"> | 76 <link rel="import" href="foo/bar.html"> |
70 <div>b|lib/foo.html</div> | 77 <div>b|lib/foo.html</div> |
71 ''', | 78 ''', |
72 'b|lib/foo/bar.html': '<div>b|lib/foo/bar.html</div>', | 79 'b|lib/foo/bar.html': '<div>b|lib/foo/bar.html</div>', |
73 }, { | 80 }, |
74 'a|web/result.txt': ''' | 81 { |
| 82 'a|web/result.txt': ''' |
75 (a|web/foo.html, a|lib/foo.html, b|lib/foo/bar.html, b|lib/foo.html, a|web
/index.html) | 83 (a|web/foo.html, a|lib/foo.html, b|lib/foo/bar.html, b|lib/foo.html, a|web
/index.html) |
76 ''', | 84 ''', |
77 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 85 }, |
| 86 messages: [], |
| 87 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
78 | 88 |
79 testPhases('cycle', phases, { | 89 testPhases( |
80 'a|web/index.html': ''' | 90 'cycle', |
| 91 phases, |
| 92 { |
| 93 'a|web/index.html': ''' |
81 <link rel="import" href="packages/a/foo.html"> | 94 <link rel="import" href="packages/a/foo.html"> |
82 <div>a|web/index.html</div> | 95 <div>a|web/index.html</div> |
83 ''', | 96 ''', |
84 'a|lib/foo.html': ''' | 97 'a|lib/foo.html': ''' |
85 <link rel="import" href="bar.html"> | 98 <link rel="import" href="bar.html"> |
86 <div>a|lib/foo.html</div>''', | 99 <div>a|lib/foo.html</div>''', |
87 'a|lib/bar.html': ''' | 100 'a|lib/bar.html': ''' |
88 <link rel="import" href="foo.html"> | 101 <link rel="import" href="foo.html"> |
89 <div>a|lib/bar.html</div>''', | 102 <div>a|lib/bar.html</div>''', |
90 }, { | 103 }, |
91 'a|web/result.txt': ''' | 104 { |
| 105 'a|web/result.txt': ''' |
92 (a|lib/bar.html, a|lib/foo.html, a|web/index.html) | 106 (a|lib/bar.html, a|lib/foo.html, a|web/index.html) |
93 ''', | 107 ''', |
94 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 108 }, |
| 109 messages: [], |
| 110 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
95 | 111 |
96 testPhases('deep imports', phases, { | 112 testPhases( |
97 'a|web/index.html': ''' | 113 'deep imports', |
| 114 phases, |
| 115 { |
| 116 'a|web/index.html': ''' |
98 <link rel="import" href="packages/a/foo.html"> | 117 <link rel="import" href="packages/a/foo.html"> |
99 <div>a|web/index.html</div> | 118 <div>a|web/index.html</div> |
100 ''', | 119 ''', |
101 'a|lib/foo.html': ''' | 120 'a|lib/foo.html': ''' |
102 <link rel="import" href="one/bar.html"> | 121 <link rel="import" href="one/bar.html"> |
103 <div>a|lib/foo.html</div>''', | 122 <div>a|lib/foo.html</div>''', |
104 'a|lib/one/bar.html': ''' | 123 'a|lib/one/bar.html': ''' |
105 <link rel="import" href="two/baz.html"> | 124 <link rel="import" href="two/baz.html"> |
106 <div>a|lib/one/bar.html</div>''', | 125 <div>a|lib/one/bar.html</div>''', |
107 'a|lib/one/two/baz.html': ''' | 126 'a|lib/one/two/baz.html': ''' |
108 <link rel="import" href="three/zap.html"> | 127 <link rel="import" href="three/zap.html"> |
109 <div>a|lib/one/two/baz.html</div>''', | 128 <div>a|lib/one/two/baz.html</div>''', |
110 'a|lib/one/two/three/zap.html': ''' | 129 'a|lib/one/two/three/zap.html': ''' |
111 <div>a|lib/one/two/three/zap.html</div>''', | 130 <div>a|lib/one/two/three/zap.html</div>''', |
112 }, { | 131 }, |
113 'a|web/result.txt': | 132 { |
114 '(a|lib/one/two/three/zap.html, a|lib/one/two/baz.html, ' | 133 'a|web/result.txt': |
115 'a|lib/one/bar.html, a|lib/foo.html, a|web/index.html)', | 134 '(a|lib/one/two/three/zap.html, a|lib/one/two/baz.html, ' |
116 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 135 'a|lib/one/bar.html, a|lib/foo.html, a|web/index.html)', |
| 136 }, |
| 137 messages: [], |
| 138 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
117 } | 139 } |
OLD | NEW |