progtest: Do not run tests async on console
Performance hit is too great; automated tests need to be _fast_! * src/AsyncTestRunner.js: New TestRunner subtype. * src/TestRunner.js (_runAsync): Rename to virtual protected `runAllTests'; this method is overridden by aforementioned subtype. * src/env.js: Use it.master v2.11.0
parent
6cefab5344
commit
0cb43d5e8a
|
@ -0,0 +1,74 @@
|
||||||
|
/**
|
||||||
|
* Async test case runner
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 R-T Specialty, LLC.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
module.exports = Class( 'TestRunner' )
|
||||||
|
.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();
|
||||||
|
const result = this.runTest( dfn, results.length, total );
|
||||||
|
|
||||||
|
results.push( result );
|
||||||
|
|
||||||
|
setTimeout( runNext, 0 );
|
||||||
|
};
|
||||||
|
|
||||||
|
runNext();
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
} );
|
|
@ -76,49 +76,29 @@ module.exports = Class( 'TestRunner',
|
||||||
|
|
||||||
this._reporter.preRun( total );
|
this._reporter.preRun( total );
|
||||||
|
|
||||||
return this._runAsync( dfns ).then(
|
return this.runAllTests( dfns ).then(
|
||||||
results => ( this._reporter.done( results ), results )
|
results => ( this._reporter.done( results ), results )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run all tests asynchronously
|
* Run all tests
|
||||||
*
|
*
|
||||||
* TODO: This significantly slows down the runner! The better option
|
* This may be overridden by subtypes to change how the tests are run
|
||||||
* would be to go back to sync and put it in a Web Worker in the client,
|
* (for example, to run each asynchronously).
|
||||||
* which would also async updating of the UI.
|
|
||||||
*
|
*
|
||||||
* @param {Array<TestCase>} dfns test case definitions
|
* @param {Array<TestCase>} dfns test case definitions
|
||||||
*
|
*
|
||||||
* @return {Promise} promise to complete test cases, yielding results
|
* @return {Promise} promise to complete test cases, yielding results
|
||||||
*/
|
*/
|
||||||
'private _runAsync'( dfns )
|
'virtual protected runAllTests'( dfns )
|
||||||
{
|
{
|
||||||
const total = dfns.length;
|
const total = dfns.length;
|
||||||
|
|
||||||
return new Promise( ( resolve, reject ) =>
|
return Promise.resolve(
|
||||||
{
|
dfns.map( ( dfn, i ) => this.runTest( dfn, ( i + 1 ), total ) )
|
||||||
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 );
|
|
||||||
|
|
||||||
setTimeout( runNext, 0 );
|
|
||||||
};
|
|
||||||
|
|
||||||
runNext();
|
|
||||||
} );
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +111,7 @@ module.exports = Class( 'TestRunner',
|
||||||
*
|
*
|
||||||
* @return {Object<desc,i,total,failures>} test results
|
* @return {Object<desc,i,total,failures>} test results
|
||||||
*/
|
*/
|
||||||
'private _runTest'( { description: desc, data, expect }, test_i, total )
|
'protected runTest'( { description: desc, data, expect }, test_i, total )
|
||||||
{
|
{
|
||||||
// no input map---#rate uses params directly
|
// no input map---#rate uses params directly
|
||||||
const result = this._tryRun( data );
|
const result = this._tryRun( data );
|
||||||
|
|
|
@ -26,6 +26,7 @@ const yaml_reader = require( 'js-yaml' );
|
||||||
const {
|
const {
|
||||||
TestCase,
|
TestCase,
|
||||||
TestRunner,
|
TestRunner,
|
||||||
|
AsyncTestRunner,
|
||||||
|
|
||||||
reader: {
|
reader: {
|
||||||
ConstResolver,
|
ConstResolver,
|
||||||
|
@ -41,13 +42,26 @@ const {
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
console: ( program, stdout, reporter ) =>
|
console: ( program, stdout ) => module.exports.common(
|
||||||
{
|
program,
|
||||||
const runner = TestRunner(
|
stdout,
|
||||||
( reporter || ConsoleTestReporter( stdout ) ),
|
TestRunner(
|
||||||
|
ConsoleTestReporter( stdout ),
|
||||||
program
|
program
|
||||||
);
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
browser: ( program, stdout ) => module.exports.common(
|
||||||
|
program,
|
||||||
|
stdout,
|
||||||
|
AsyncTestRunner(
|
||||||
|
ConsoleTestReporter.use( HtmlConsoleOutput )( stdout ),
|
||||||
|
program
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
common: ( program, stdout, runner ) =>
|
||||||
|
{
|
||||||
const reader = YamlTestReader
|
const reader = YamlTestReader
|
||||||
.use( DateResolver )
|
.use( DateResolver )
|
||||||
.use( ConstResolver( program ) )
|
.use( ConstResolver( program ) )
|
||||||
|
@ -71,10 +85,4 @@ module.exports = {
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
|
|
||||||
browser: ( program, stdout ) => module.exports.console(
|
|
||||||
program,
|
|
||||||
stdout,
|
|
||||||
ConsoleTestReporter.use( HtmlConsoleOutput )( stdout )
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue