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