OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview A mocha adapter for BrowserTests. To use, include mocha.js and | 6 * @fileoverview A mocha adapter for BrowserTests. To use, include mocha.js and |
7 * mocha_adapter.js in a WebUIBrowserTest's extraLibraries array. | 7 * mocha_adapter.js in a WebUIBrowserTest's extraLibraries array. |
8 */ | 8 */ |
9 | 9 |
10 // NOTE: When defining TEST_F() functions that use Mocha, use 'var self = this' | 10 // NOTE: When defining TEST_F() functions that use Mocha, use 'var self = this' |
(...skipping 17 matching lines...) Expand all Loading... |
28 passes++; | 28 passes++; |
29 }); | 29 }); |
30 | 30 |
31 // Report failures. Mocha only catches "assert" failures, because "expect" | 31 // Report failures. Mocha only catches "assert" failures, because "expect" |
32 // failures are caught by test_api.js. | 32 // failures are caught by test_api.js. |
33 runner.on('fail', function(test, err) { | 33 runner.on('fail', function(test, err) { |
34 failures++; | 34 failures++; |
35 var message = 'Mocha test failed: ' + test.fullTitle() + '\n'; | 35 var message = 'Mocha test failed: ' + test.fullTitle() + '\n'; |
36 | 36 |
37 // Remove unhelpful mocha lines from stack trace. | 37 // Remove unhelpful mocha lines from stack trace. |
38 var stack = err.stack.split('\n'); | 38 if (err.stack) { |
39 for (var i = 0; i < stack.length; i++) { | 39 var stack = err.stack.split('\n'); |
40 if (stack[i].indexOf('mocha.js:') == -1) | 40 for (var i = 0; i < stack.length; i++) { |
41 message += stack[i] + '\n'; | 41 if (stack[i].indexOf('mocha.js:') == -1) |
| 42 message += stack[i] + '\n'; |
| 43 } |
| 44 } else { |
| 45 message += err.toString(); |
42 } | 46 } |
43 | 47 |
44 console.error(message); | 48 console.error(message); |
45 }); | 49 }); |
46 | 50 |
47 // Report the results to the test API. | 51 // Report the results to the test API. |
48 runner.on('end', function() { | 52 runner.on('end', function() { |
49 if (failures == 0) { | 53 if (failures == 0) { |
50 if (passes > 0) | 54 if (passes > 0) |
51 testDone(); | 55 testDone(); |
(...skipping 13 matching lines...) Expand all Loading... |
65 mocha.setup({ | 69 mocha.setup({ |
66 // Use TDD interface instead of BDD. | 70 // Use TDD interface instead of BDD. |
67 ui: 'tdd', | 71 ui: 'tdd', |
68 // Use custom reporter to interface with BrowserTests. | 72 // Use custom reporter to interface with BrowserTests. |
69 reporter: BrowserTestReporter, | 73 reporter: BrowserTestReporter, |
70 // Mocha timeouts are set to 2 seconds initially. This isn't nearly enough for | 74 // Mocha timeouts are set to 2 seconds initially. This isn't nearly enough for |
71 // slower bots (e.g., Dr. Memory). Disable timeouts globally, because the C++ | 75 // slower bots (e.g., Dr. Memory). Disable timeouts globally, because the C++ |
72 // will handle it (and has scaled timeouts for slower bots). | 76 // will handle it (and has scaled timeouts for slower bots). |
73 enableTimeouts: false, | 77 enableTimeouts: false, |
74 }); | 78 }); |
OLD | NEW |