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

Side by Side Diff: test/runner/pub_serve_test.dart

Issue 1087303004: Add support for user-defined HTML files. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « test/runner/browser/runner_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4
5 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
(...skipping 27 matching lines...) Expand all
38 38
39 new Directory(p.join(_sandbox, "test")).createSync(); 39 new Directory(p.join(_sandbox, "test")).createSync();
40 40
41 new File(p.join(_sandbox, "test", "my_test.dart")).writeAsStringSync(""" 41 new File(p.join(_sandbox, "test", "my_test.dart")).writeAsStringSync("""
42 import 'package:test/test.dart'; 42 import 'package:test/test.dart';
43 43
44 void main() { 44 void main() {
45 test("test", () => expect(true, isTrue)); 45 test("test", () => expect(true, isTrue));
46 } 46 }
47 """); 47 """);
48 });
49 48
50 tearDown(() { 49 new Directory(p.join(_sandbox, "lib")).createSync();
51 new Directory(_sandbox).deleteSync(recursive: true);
52 });
53 50
54 group("with transformed tests", () { 51 new File(p.join(_sandbox, "lib", "myapp.dart")).writeAsStringSync("""
55 setUp(() {
56 new Directory(p.join(_sandbox, "lib")).createSync();
57
58 new File(p.join(_sandbox, "lib", "myapp.dart")).writeAsStringSync("""
59 import 'package:barback/barback.dart'; 52 import 'package:barback/barback.dart';
60 53
61 class MyTransformer extends Transformer { 54 class MyTransformer extends Transformer {
62 final allowedExtensions = '.dart'; 55 final allowedExtensions = '.dart';
63 56
64 MyTransformer.asPlugin(); 57 MyTransformer.asPlugin();
65 58
66 Future apply(Transform transform) { 59 Future apply(Transform transform) {
67 return transform.primaryInput.readAsString().then((contents) { 60 return transform.primaryInput.readAsString().then((contents) {
68 print("contents: \$contents"); 61 print("contents: \$contents");
69 print("new contents: \${contents.replaceAll("isFalse", "isTrue")}"); 62 print("new contents: \${contents.replaceAll("isFalse", "isTrue")}");
70 transform.addOutput(new Asset.fromString( 63 transform.addOutput(new Asset.fromString(
71 transform.primaryInput.id, 64 transform.primaryInput.id,
72 contents.replaceAll("isFalse", "isTrue"))); 65 contents.replaceAll("isFalse", "isTrue")));
73 }); 66 });
74 } 67 }
75 } 68 }
76 """); 69 """);
77 70
78 var pubGetResult = runPub(['get'], workingDirectory: _sandbox); 71 var pubGetResult = runPub(['get'], workingDirectory: _sandbox);
79 expect(pubGetResult.exitCode, equals(0)); 72 expect(pubGetResult.exitCode, equals(0));
80 }); 73 });
81 74
75 tearDown(() {
76 new Directory(_sandbox).deleteSync(recursive: true);
77 });
78
79 group("with transformed tests", () {
82 test("runs those tests in the VM", () { 80 test("runs those tests in the VM", () {
83 return startPub(['serve', '--port', '0'], workingDirectory: _sandbox) 81 return startPub(['serve', '--port', '0'], workingDirectory: _sandbox)
84 .then((process) { 82 .then((process) {
85 return _lines.bind(process.stdout) 83 return _lines.bind(process.stdout)
86 .firstWhere(_servingRegExp.hasMatch) 84 .firstWhere(_servingRegExp.hasMatch)
87 .then((line) { 85 .then((line) {
88 var match = _servingRegExp.firstMatch(line); 86 var match = _servingRegExp.firstMatch(line);
89 87
90 try { 88 try {
91 var result = runUnittest(['--pub-serve=${match[1]}'], 89 var result = runUnittest(['--pub-serve=${match[1]}'],
92 workingDirectory: _sandbox); 90 workingDirectory: _sandbox);
93 expect(result.exitCode, equals(0)); 91 expect(result.exitCode, equals(0));
94 expect(result.stdout, contains('+1: All tests passed!')); 92 expect(result.stdout, contains('+1: All tests passed!'));
95 } finally { 93 } finally {
96 process.kill(); 94 process.kill();
97 } 95 }
98 }); 96 });
99 }); 97 });
100 }); 98 });
101 99
102 test("runs those tests in the browser", () { 100 test("runs those tests on Chrome", () {
103 return startPub(['serve', '--port', '0'], 101 return startPub(['serve', '--port', '0'],
104 workingDirectory: _sandbox) 102 workingDirectory: _sandbox)
105 .then((process) { 103 .then((process) {
106 return _lines.bind(process.stdout) 104 return _lines.bind(process.stdout)
107 .firstWhere(_servingRegExp.hasMatch) 105 .firstWhere(_servingRegExp.hasMatch)
108 .then((line) { 106 .then((line) {
109 var match = _servingRegExp.firstMatch(line); 107 var match = _servingRegExp.firstMatch(line);
110 108
111 try { 109 try {
112 var result = runUnittest( 110 var result = runUnittest(
113 ['--pub-serve=${match[1]}', '-p', 'chrome'], 111 ['--pub-serve=${match[1]}', '-p', 'chrome'],
114 workingDirectory: _sandbox); 112 workingDirectory: _sandbox);
115 expect(result.exitCode, equals(0)); 113 expect(result.exitCode, equals(0));
116 expect(result.stdout, contains('+1: All tests passed!')); 114 expect(result.stdout, contains('+1: All tests passed!'));
117 } finally { 115 } finally {
118 process.kill(); 116 process.kill();
119 } 117 }
120 }); 118 });
121 }); 119 });
122 }); 120 });
123 121
122 test("runs those tests on content shell", () {
123 return startPub(['serve', '--port', '0'],
124 workingDirectory: _sandbox)
125 .then((process) {
126 return _lines.bind(process.stdout)
127 .firstWhere(_servingRegExp.hasMatch)
128 .then((line) {
129 var match = _servingRegExp.firstMatch(line);
130
131 try {
132 var result = runUnittest(
133 ['--pub-serve=${match[1]}', '-p', 'content-shell'],
134 workingDirectory: _sandbox);
135 expect(result.exitCode, equals(0));
136 expect(result.stdout, contains('+1: All tests passed!'));
137 } finally {
138 process.kill();
139 }
140 });
141 });
142 });
143
124 test("gracefully handles pub serve running on the wrong directory for " 144 test("gracefully handles pub serve running on the wrong directory for "
125 "VM tests", () { 145 "VM tests", () {
126 new Directory(p.join(_sandbox, "web")).createSync(); 146 new Directory(p.join(_sandbox, "web")).createSync();
127 147
128 return startPub(['serve', '--port', '0', 'web'], 148 return startPub(['serve', '--port', '0', 'web'],
129 workingDirectory: _sandbox) 149 workingDirectory: _sandbox)
130 .then((process) { 150 .then((process) {
131 return _lines.bind(process.stdout) 151 return _lines.bind(process.stdout)
132 .firstWhere(_servingRegExp.hasMatch) 152 .firstWhere(_servingRegExp.hasMatch)
133 .then((line) { 153 .then((line) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 \$include: test/**_test.dart 229 \$include: test/**_test.dart
210 ''')); 230 '''));
211 } finally { 231 } finally {
212 process.kill(); 232 process.kill();
213 } 233 }
214 }); 234 });
215 }); 235 });
216 }); 236 });
217 }); 237 });
218 238
239 group("uses a custom HTML file", () {
240 setUp(() {
241 new File(p.join(_sandbox, "test", "test.dart")).writeAsStringSync("""
242 import 'dart:html';
243
244 import 'package:test/test.dart';
245
246 void main() {
247 test("failure", () {
248 expect(document.query('#foo'), isNull);
249 });
250 }
251 """);
252
253 new File(p.join(_sandbox, "test", "test.html")).writeAsStringSync("""
254 <html>
255 <head>
256 <link rel='x-dart-test' href='test.dart'>
257 <script src="packages/test/dart.js"></script>
258 </head>
259 <body>
260 <div id="foo"></div>
261 </body>
262 """);
263 });
264
265 test("on Chrome", () {
266 return startPub(['serve', '--port', '0'],
267 workingDirectory: _sandbox)
268 .then((process) {
269 return _lines.bind(process.stdout)
270 .firstWhere(_servingRegExp.hasMatch)
271 .then((line) {
272 var match = _servingRegExp.firstMatch(line);
273
274 try {
275 var result = runUnittest(
276 ['--pub-serve=${match[1]}', '-p', 'chrome'],
277 workingDirectory: _sandbox);
278 expect(result.exitCode, equals(0));
279 expect(result.stdout, contains('+1: All tests passed!'));
280 } finally {
281 process.kill();
282 }
283 });
284 });
285 });
286
287 test("on content shell", () {
288 return startPub(['serve', '--port', '0'],
289 workingDirectory: _sandbox)
290 .then((process) {
291 return _lines.bind(process.stdout)
292 .firstWhere(_servingRegExp.hasMatch)
293 .then((line) {
294 var match = _servingRegExp.firstMatch(line);
295
296 try {
297 var result = runUnittest(
298 ['--pub-serve=${match[1]}', '-p', 'content-shell'],
299 workingDirectory: _sandbox);
300 expect(result.exitCode, equals(0));
301 expect(result.stdout, contains('+1: All tests passed!'));
302 } finally {
303 process.kill();
304 }
305 });
306 });
307 });
308 });
309
219 test("gracefully handles pub serve not running for VM tests", () { 310 test("gracefully handles pub serve not running for VM tests", () {
220 var result = runUnittest(['--pub-serve=54321'], 311 var result = runUnittest(['--pub-serve=54321'],
221 workingDirectory: _sandbox); 312 workingDirectory: _sandbox);
222 expect(result.stdout, allOf([ 313 expect(result.stdout, allOf([
223 contains('-1: load error'), 314 contains('-1: load error'),
224 contains(''' 315 contains('''
225 Failed to load "test/my_test.dart": 316 Failed to load "test/my_test.dart":
226 Error getting http://localhost:54321/my_test.dart.vm_test.dart: Connection ref used 317 Error getting http://localhost:54321/my_test.dart.vm_test.dart: Connection ref used
227 Make sure "pub serve" is running.''') 318 Make sure "pub serve" is running.''')
228 ])); 319 ]));
(...skipping 21 matching lines...) Expand all
250 workingDirectory: _sandbox); 341 workingDirectory: _sandbox);
251 expect(result.stdout, allOf([ 342 expect(result.stdout, allOf([
252 contains('-1: load error'), 343 contains('-1: load error'),
253 contains( 344 contains(
254 'Failed to load "my_test.dart": When using "pub serve", all test ' 345 'Failed to load "my_test.dart": When using "pub serve", all test '
255 'files must be in test/.\n') 346 'files must be in test/.\n')
256 ])); 347 ]));
257 expect(result.exitCode, equals(1)); 348 expect(result.exitCode, equals(1));
258 }); 349 });
259 } 350 }
OLDNEW
« no previous file with comments | « test/runner/browser/runner_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698