OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, 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 |
| 5 /** End-to-end tests for the [Compiler] API. */ |
| 6 library compiler_test; |
| 7 |
| 8 import 'package:logging/logging.dart' show Level; |
| 9 import 'package:unittest/compact_vm_config.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:polymer/src/messages.dart'; |
| 12 |
| 13 import 'testing.dart'; |
| 14 |
| 15 main() { |
| 16 useCompactVMConfiguration(); |
| 17 |
| 18 test('recursive dependencies', () { |
| 19 var messages = new Messages.silent(); |
| 20 var compiler = createCompiler({ |
| 21 'index.html': '<head>' |
| 22 '<link rel="import" href="foo.html">' |
| 23 '<link rel="import" href="bar.html">' |
| 24 '<body><x-foo></x-foo><x-bar></x-bar>' |
| 25 '<script type="application/dart">main() {}</script>', |
| 26 'foo.html': '<head><link rel="import" href="bar.html">' |
| 27 '<body><polymer-element name="x-foo" constructor="Foo">' |
| 28 '<template><x-bar>', |
| 29 'bar.html': '<head><link rel="import" href="foo.html">' |
| 30 '<body><polymer-element name="x-bar" constructor="Boo">' |
| 31 '<template><x-foo>', |
| 32 }, messages); |
| 33 |
| 34 compiler.run().then(expectAsync1((e) { |
| 35 MockFileSystem fs = compiler.fileSystem; |
| 36 expect(fs.readCount, equals({ |
| 37 'index.html': 1, |
| 38 'foo.html': 1, |
| 39 'bar.html': 1 |
| 40 }), reason: 'Actual:\n ${fs.readCount}'); |
| 41 |
| 42 var outputs = compiler.output.map((o) => o.path); |
| 43 expect(outputs, equals([ |
| 44 'out/foo.html.dart', |
| 45 'out/foo.html.dart.map', |
| 46 'out/bar.html.dart', |
| 47 'out/bar.html.dart.map', |
| 48 'out/index.html.dart', |
| 49 'out/index.html.dart.map', |
| 50 'out/index.html_bootstrap.dart', |
| 51 'out/index.html', |
| 52 ])); |
| 53 })); |
| 54 }); |
| 55 |
| 56 group('missing files', () { |
| 57 test('main script', () { |
| 58 var messages = new Messages.silent(); |
| 59 var compiler = createCompiler({ |
| 60 'index.html': '<head></head><body>' |
| 61 '<script type="application/dart" src="notfound.dart"></script>' |
| 62 '</body>', |
| 63 }, messages); |
| 64 |
| 65 compiler.run().then(expectAsync1((e) { |
| 66 var msgs = messages.messages.where((m) => |
| 67 m.message.contains('unable')).toList(); |
| 68 |
| 69 expect(msgs.length, 1); |
| 70 expect(msgs[0].level, Level.SEVERE); |
| 71 expect(msgs[0].message, contains('unable to open file')); |
| 72 expect(msgs[0].span, isNotNull); |
| 73 expect(msgs[0].span.sourceUrl, 'index.html'); |
| 74 |
| 75 MockFileSystem fs = compiler.fileSystem; |
| 76 expect(fs.readCount, { 'index.html': 1, 'notfound.dart': 1 }); |
| 77 |
| 78 var outputs = compiler.output.map((o) => o.path.toString()); |
| 79 expect(outputs, []); |
| 80 })); |
| 81 }); |
| 82 |
| 83 test('component html', () { |
| 84 var messages = new Messages.silent(); |
| 85 var compiler = createCompiler({ |
| 86 'index.html': '<head>' |
| 87 '<link rel="import" href="notfound.html">' |
| 88 '<body><x-foo>' |
| 89 '<script type="application/dart">main() {}</script>', |
| 90 }, messages); |
| 91 |
| 92 compiler.run().then(expectAsync1((e) { |
| 93 var msgs = messages.messages.where((m) => |
| 94 m.message.contains('unable')).toList(); |
| 95 |
| 96 expect(msgs.length, 1); |
| 97 expect(msgs[0].level, Level.SEVERE); |
| 98 expect(msgs[0].message, contains('unable to open file')); |
| 99 expect(msgs[0].span, isNotNull); |
| 100 expect(msgs[0].span.sourceUrl, 'index.html'); |
| 101 |
| 102 MockFileSystem fs = compiler.fileSystem; |
| 103 expect(fs.readCount, { 'index.html': 1, 'notfound.html': 1 }); |
| 104 |
| 105 var outputs = compiler.output.map((o) => o.path.toString()); |
| 106 expect(outputs, []); |
| 107 })); |
| 108 }); |
| 109 |
| 110 test('component script', () { |
| 111 var messages = new Messages.silent(); |
| 112 var compiler = createCompiler({ |
| 113 'index.html': '<head>' |
| 114 '<link rel="import" href="foo.html">' |
| 115 '<body><x-foo></x-foo>' |
| 116 '<script type="application/dart">main() {}</script>' |
| 117 '</body>', |
| 118 'foo.html': '<body><polymer-element name="x-foo" constructor="Foo">' |
| 119 '<template></template>' |
| 120 '<script type="application/dart" src="notfound.dart"></script>', |
| 121 }, messages); |
| 122 |
| 123 compiler.run().then(expectAsync1((e) { |
| 124 var msgs = messages.messages.where((m) => |
| 125 m.message.contains('unable')).toList(); |
| 126 |
| 127 expect(msgs.length, 1); |
| 128 expect(msgs[0].level, Level.SEVERE); |
| 129 expect(msgs[0].message, contains('unable to open file')); |
| 130 |
| 131 MockFileSystem fs = compiler.fileSystem; |
| 132 expect(fs.readCount, |
| 133 { 'index.html': 1, 'foo.html': 1, 'notfound.dart': 1 }); |
| 134 |
| 135 var outputs = compiler.output.map((o) => o.path.toString()); |
| 136 expect(outputs, []); |
| 137 })); |
| 138 }); |
| 139 }); |
| 140 } |
OLD | NEW |