diff options
author | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-02-16 14:41:39 -0500 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-02-19 15:21:14 -0500 |
commit | 0b433e86f4497fa285bcf8a37d0dcd39bfa09c7e (patch) | |
tree | 0103c1c471a0d70a12b497ccecfc71ad39540841 /progtest | |
parent | f788edd675e3662192c2421ae142fb1f42d3da49 (diff) | |
download | tame-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')
-rw-r--r-- | progtest/src/TestRunner.js | 46 | ||||
-rw-r--r-- | progtest/test/TestRunnerTest.js | 32 |
2 files changed, 59 insertions, 19 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(); + } ); }, diff --git a/progtest/test/TestRunnerTest.js b/progtest/test/TestRunnerTest.js index fc06e04..eff50eb 100644 --- a/progtest/test/TestRunnerTest.js +++ b/progtest/test/TestRunnerTest.js @@ -86,20 +86,24 @@ describe( "TestRunner", () => ] ]; - const results = Sut( NullTestReporter(), program ) - .runTests( test_cases ); - - test_cases.forEach( ( test_case, i ) => - { - const result = results[ i ]; - - expect( result.desc ).to.equal( test_case.description ); - expect( result.i ).to.equal( i ); - expect( result.total ).to.equal( - Object.keys( test_case.expect ).length - ); - expect( result.failures ).to.deep.equal( expect_failures[ i ] ); - } ); + Sut( NullTestReporter(), program ) + .runTests( test_cases ) + .then( results => + { + test_cases.forEach( ( test_case, i ) => + { + const result = results[ i ]; + + expect( result.desc ).to.equal( test_case.description ); + expect( result.i ).to.equal( i ); + expect( result.total ).to.equal( + Object.keys( test_case.expect ).length + ); + expect( result.failures ).to.deep.equal( + expect_failures[ i ] + ); + } ); + } ); } ); |