2018-03-05 16:22:13 -05:00
|
|
|
/**
|
|
|
|
* Async test case runner
|
|
|
|
*
|
2020-03-06 11:05:18 -05:00
|
|
|
* Copyright (C) 2014-2020 Ryan Specialty Group, LLC.
|
2018-03-05 16:22:13 -05:00
|
|
|
*
|
|
|
|
* This file is part of TAME.
|
|
|
|
*
|
|
|
|
* TAME is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { Class } = require( 'easejs' );
|
|
|
|
const TestRunner = require( './TestRunner' );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run test cases asynchronously and report results
|
|
|
|
*
|
|
|
|
* This allows the browser to repaint between cases.
|
|
|
|
*/
|
2019-05-06 15:53:19 -04:00
|
|
|
module.exports = Class( 'AsyncTestRunner' )
|
2018-03-05 16:22:13 -05:00
|
|
|
.extend( TestRunner,
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
'override protected runAllTests'( dfns )
|
|
|
|
{
|
|
|
|
const total = dfns.length;
|
|
|
|
|
|
|
|
return new Promise( ( resolve, reject ) =>
|
|
|
|
{
|
|
|
|
const results = [];
|
|
|
|
|
|
|
|
const runNext = () =>
|
|
|
|
{
|
|
|
|
if ( dfns.length === 0 )
|
|
|
|
{
|
|
|
|
resolve( results );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dfn = dfns.shift();
|
2019-05-06 15:53:19 -04:00
|
|
|
const result = this.runTest( dfn, ( results.length + 1 ), total );
|
2018-03-05 16:22:13 -05:00
|
|
|
|
|
|
|
results.push( result );
|
|
|
|
|
|
|
|
setTimeout( runNext, 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
runNext();
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
} );
|