Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-16 14:41:39 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-02-19 15:21:14 -0500
commit0b433e86f4497fa285bcf8a37d0dcd39bfa09c7e (patch)
tree0103c1c471a0d70a12b497ccecfc71ad39540841 /progtest/src
parentf788edd675e3662192c2421ae142fb1f42d3da49 (diff)
downloadtame-0b433e86f4497fa285bcf8a37d0dcd39bfa09c7e.tar.gz
tame-0b433e86f4497fa285bcf8a37d0dcd39bfa09c7e.tar.bz2
tame-0b433e86f4497fa285bcf8a37d0dcd39bfa09c7e.zip
progtest: Async run each test serially
If that makes sense. The problem is that the browser needs to repaint after each test is run. See code comments.
Diffstat (limited to 'progtest/src')
-rw-r--r--progtest/src/TestRunner.js46
1 files changed, 41 insertions, 5 deletions
diff --git a/progtest/src/TestRunner.js b/progtest/src/TestRunner.js
index 9269018..d24f38f 100644
--- a/progtest/src/TestRunner.js
+++ b/progtest/src/TestRunner.js
@@ -68,7 +68,7 @@ module.exports = Class( 'TestRunner',
*
* @param {Array<TestCase>} dfns array of TestCases
*
- * @return {Array<Object<desc,i,total,failures>>} results
+ * @return {Promise} promise to complete test cases, yielding results
*/
'public runTests'( dfns )
{
@@ -76,13 +76,49 @@ module.exports = Class( 'TestRunner',
this._reporter.preRun( total );
- const results = dfns.map(
- ( test, i ) => this._runTest( test, i, total )
+ return this._runAsync( dfns ).then(
+ results => this._reporter.done( results )
);
+ },
+
+
+ /**
+ * Run all tests asynchronously
+ *
+ * TODO: This significantly slows down the runner! The better option
+ * would be to go back to sync and put it in a Web Worker in the client,
+ * which would also async updating of the UI.
+ *
+ * @param {Array<TestCase>} dfns test case definitions
+ *
+ * @return {Promise} promise to complete test cases, yielding results
+ */
+ 'private _runAsync'( dfns )
+ {
+ const total = dfns.length;
+
+ return new Promise( resolve =>
+ {
+ const results = [];
+
+ const runNext = () =>
+ {
+ if ( dfns.length === 0 )
+ {
+ resolve( results );
+ return;
+ }
+
+ const dfn = dfns.shift();
+ const result = this._runTest( dfn, results.length, total );
+
+ results.push( result );
- this._reporter.done( results );
+ setTimeout( runNext, 0 );
+ };
- return results;
+ runNext();
+ } );
},