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 Framework for running JavaScript tests of Polymer elements. | 6 * @fileoverview Framework for running JavaScript tests of Polymer elements. |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * Test fixture for Polymer element testing. | 10 * Test fixture for Polymer element testing. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 */ | 88 */ |
89 PolymerTest.getLibraries = function(basePath) { | 89 PolymerTest.getLibraries = function(basePath) { |
90 // Ensure basePath ends in '/'. | 90 // Ensure basePath ends in '/'. |
91 if (basePath.length && basePath[basePath.length - 1] != '/') | 91 if (basePath.length && basePath[basePath.length - 1] != '/') |
92 basePath += '/'; | 92 basePath += '/'; |
93 | 93 |
94 return PolymerTest.prototype.extraLibraries.map(function(library) { | 94 return PolymerTest.prototype.extraLibraries.map(function(library) { |
95 return basePath + library; | 95 return basePath + library; |
96 }); | 96 }); |
97 }; | 97 }; |
| 98 |
| 99 /** |
| 100 * Returns a promise which asynchronously calls |fn| and is also resolved |
| 101 * asynchronously. Repeated calls to this function ensure each call waits for |
| 102 * the previous promise to resolve, allowing any setTimeouts called by the prior |
| 103 * function to be queued beforehand. For example: |
| 104 * PolymerTest.async(fn1); PolymerTest.async(fn2).then(success, failure); |
| 105 * If fn1 calls setTimeout(asyncFn), fn2 won't be called until after asyncFn is |
| 106 * called. |
| 107 * @param {function()=} opt_fn |
| 108 * @return {Promise} |
| 109 */ |
| 110 PolymerTest.async = function(opt_fn) { |
| 111 PolymerTest.lastPromise_ = PolymerTest.lastPromise_.then(function() { |
| 112 return new Promise(function(resolve) { |
| 113 if (opt_fn) |
| 114 setTimeout(opt_fn); |
| 115 setTimeout(resolve); |
| 116 }); |
| 117 }); |
| 118 return PolymerTest.lastPromise_; |
| 119 }; |
| 120 |
| 121 /** @private {Promise} */ |
| 122 PolymerTest.lastPromise_ = Promise.resolve(); |
OLD | NEW |