Nickolay - Test.Run-0.10
Name
Test.Run.Harness - Abstract base class for test harness
SYNOPSIS
Test.Run.Harness.Browser.Multi.configure({
title : 'Module.Stub Test Suite',
passThroughEx : true,
preload : [
'/jsan/Task/Joose/Core.js',
"/jsan/JooseX/SimpleRequest.js",
'/jsan/Task/JooseX/Namespace/Depended/Web.js',
{
text : "JooseX.Namespace.Depended.Manager.my.INC = " + Ext.encode(INC)
}
]
})
Test.Run.Harness.Browser.Multi.start(
'/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/010_sanity.t.js',
'/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/020_basics.t.js'
)
DESCRIPTION
Test.Run.Harness
is an abstract base harness class in Test.Run hierarchy. This class provides no UI,
you should use one of it subclasses, for example [Test.Run.Harness.Browser.ExtJS]
USAGE
Methods
configure
void configure(Object options)
This method configure the harness instance. It just copies the passed configuration option into static instance.
options - configuration options (values of attributes for this class, see below for details)
start
void start(String url1, String url2, ...)
This method starts a whole test suite
url1, url2, ... - the variable number of test files urls
Configuration options
title
String title
The title of the test suite
passThroughEx
Boolean passThroughEx
The sign whether the each tests in suite should re-throw any exceptions caught (sometimes useful for debugging with FireBug). Defaults to 'false'.
transparentEx
Boolean transparentEx
The sign whether the each tests in suite shouldn't catch any exceptions at all. Exceptions will be thrown "as is". This is also useful for debugging. Defaults to 'false'
preload
Array preload
The array which contains the information about which files should be preloaded into each test's scope. The folloing rules applies during processing of the array:
If the string entry represent a class name (for example :
Test.Run.Test
) it is converting to the url, like "/doc/s/sa/samuraijack/Test/Run/010/lib/Test/lib/Test/Run/Test.js"All string entries starting with 'jsan:' are replaced with the link to corresponding JSAN module. For example:
jsan:Task.Joose.Core
If the entry ends with "/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/.js", its supposed to be the url and is passing without modifications.
If the entry is an Object with
text
property, then the value of that property will be evaluted in the test's global scope directly. In this way you can run arbitrary code for setup.
runCore
String runCore
Either
parallel
orsequential
. Indicates how the individual tests should be run - several at once or one-by-one.
maxThreads
Number maxThreads
The maximum number of tests running at the same time. Only applicable for
parallel
run-core.
testClass
Class testClass
The test class which will be used for running tests, defaults to Test.Run.Test.
SEE ALSO
General documentation for Joose: http://openjsan.org/go/?l=Joose
BUGS
All complex software has bugs lurking in it, and this module is no exception.
Please report any bugs through the web interface at http://github.com/SamuraiJack/test.run/issues
AUTHORS
Nickolay Platonov nplatonov@cpan.org
COPYRIGHT AND LICENSE
Copyright (c) 2010, Nickolay Platonov
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Nickolay Platonov nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Class('Test.Run.Harness', { my : { have : { title : null, testClass : Test.Run.Test, tests : null, testsByURL : null, descriptorsByURL : null, scopesByURL : null, startArgs : null, passThroughEx : false, transparentEx : false, scopeProvider : null, runCore : 'parallel', // or 'sequential' maxThreads : 4, preload : null, verbosity : 0, keepResults : false }, after : { initialize : function () { this.testsByURL = {} this.descriptorsByURL = {} this.scopesByURL = {} this.tests = [] } }, methods : { onTestUpdate : function (test, result) { }, onTestFail : function (test, exception) { }, onTestStart : function (test) { }, onTestEnd : function (test) { }, onTestSuiteStart : function () { }, onTestSuiteEnd : function () { }, configure : function (config) { Joose.O.copy(config, this) }, start : function () { var me = this this.startArgs = arguments var descriptors = [] Joose.A.each(arguments, function (desc, index) { desc = me.normalizeDescriptor(desc, index) descriptors.push(desc) me.descriptorsByURL[ desc.url ] = desc }) this.onTestSuiteStart(descriptors) this.runTestsForDescriptors(descriptors, function () { me.onTestSuiteEnd() }) }, runTestsForDescriptors : function (descriptors, callback) { var runCoreMethod = 'runCore' + Joose.S.uppercaseFirst(this.runCore) if (typeof this[ runCoreMethod ] != 'function') throw "Invalid `runCore` specified: [" + this.runCore + "]" this[ runCoreMethod ](descriptors, callback) }, runCoreParallel : function (descriptors, callback) { var me = this var processedNum = 0 var count = descriptors.length if (!count) callback() var launch = function (descriptors) { var desc = descriptors.shift() if (!desc) return me.processURL(desc, desc.index, function () { processedNum++ if (processedNum == count) callback() else launch(descriptors) }) } for (var i = 1; i <= this.maxThreads; i++) launch(descriptors) }, runCoreSequential : function (descriptors, callback) { if (descriptors.length) { var desc = descriptors.shift() var me = this this.processURL(desc, desc.index, function () { me.runCoreSequential(descriptors, callback) }) } else callback() }, setupScope : function (desc, callback) { var scopeProvider = desc.target var scopeProvideClass = eval(scopeProvider) new scopeProvideClass().setup(callback) }, cleanupScopeForURL : function (url) { var scopeProvider = this.scopesByURL[ url ] if (scopeProvider) { scopeProvider.cleanup() delete this.scopesByURL[ url ] } }, prepareScope : function (scopeProvider, desc, callback) { var me = this scopeProvider.runCode( 'StartTest = function () { __START_TEST__ = arguments };' + '__EXCEPTION_CATCHER__ = function (func) { var ex; try { func() } catch (e) { ex = e; }; return ex; };', function () { var preload = desc.preload || me.preload || [] preload = preload.concat(desc.alsoPreload || []) me.preloadScripts(scopeProvider, preload, callback) } ) }, preloadScripts : function (scopeProvider, scripts, callback) { var me = this if (scripts.length) { var script = scripts.shift() if (typeof script == 'object') scopeProvider.runCode(script.text, function () { me.preloadScripts(scopeProvider, scripts, callback) }) else scopeProvider.runScript(this.resolveURL(script), function () { me.preloadScripts(scopeProvider, scripts, callback) }) } else callback() }, normalizeDescriptor : function (desc, index) { if (typeof desc == 'string') return { url : desc, target : this.scopeProvider, index : index } if (desc.target) { var match if (match = /^=(.+)/.exec(desc.target)) desc.target = match[ 1 ] else desc.target = desc.target.replace(/^(Scope.Provider.)?/, 'Scope.Provider.') } desc.index = index return desc }, resolveURL : function (url) { return url }, processURL : function (desc, index, callback) { var me = this var url = desc.url this.cleanupScopeForURL(url) this.setupScope(desc, function (scopeProvider) { me.scopesByURL[ url ] = scopeProvider me.prepareScope(scopeProvider, desc, function () { scopeProvider.runScript(me.resolveURL(url), function () { var scope = scopeProvider.scope var startTestArgs = scope.__START_TEST__ var run = startTestArgs[0] var testClass = startTestArgs[1] var test = new (testClass || me.testClass)({ url : url, harness : me, run : run, topScope : scope, passThroughEx : me.passThroughEx, transparentEx : me.transparentEx }) me.addTest(test, index) test.start(function () { if (!me.keepResults) me.cleanupScopeForURL(url) callback && callback() }) }) }) }) }, addTest : function (test, index) { this.tests[ index ] = test this.testsByURL[ test.url ] = test }, getTestByURL : function (url) { return this.testsByURL[url] }, getTestAt : function (index) { return this.tests[ index ] }, reRunTest : function (test, callback) { this.reRunTests([ test ], callback) }, reRunTests : function (tests, callback) { var descriptors = [] Joose.A.each(tests, function (test) { descriptors.push( this.descriptorsByURL[ test.url ]) }, this) this.runTestsForDescriptors(descriptors, callback) }, reRunSuite : function () { this.start.apply(this, this.startArgs) }, isPassed : function () { var res = true Joose.O.each(this.testsByURL, function (test) { if (!test.isPassed()) res = false }) return res }, isRunning : function () { var res = false Joose.O.each(this.testsByURL, function (test) { if (!test.isFinished()) res = true }) return res } } } //eof my }) //eof Test.Run.Harness /** Name ==== Test.Run.Harness - Abstract base class for test harness SYNOPSIS ======== Test.Run.Harness.Browser.Multi.configure({ title : 'Module.Stub Test Suite', passThroughEx : true, preload : [ '/jsan/Task/Joose/Core.js', "/jsan/JooseX/SimpleRequest.js", '/jsan/Task/JooseX/Namespace/Depended/Web.js', { text : "JooseX.Namespace.Depended.Manager.my.INC = " + Ext.encode(INC) } ] }) Test.Run.Harness.Browser.Multi.start( '/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/010_sanity.t.js', '/doc/s/sa/samuraijack/Test/Run/010/lib/Test/Run/020_basics.t.js' ) DESCRIPTION =========== `Test.Run.Harness` is an abstract base harness class in Test.Run hierarchy. This class provides no UI, you should use one of it subclasses, for example [Test.Run.Harness.Browser.ExtJS] USAGE ===== Methods ------- ### configure > `void configure(Object options)` > This method configure the harness instance. It just copies the passed configuration option into static instance. > **options** - configuration options (values of attributes for this class, see below for details) ### start > `void start(String url1, String url2, ...)` > This method starts a whole test suite > **url1, url2, ...** - the variable number of test files urls Configuration options --------------------- ### title > `String title` > The title of the test suite ### passThroughEx > `Boolean passThroughEx` > The sign whether the each tests in suite should re-throw any exceptions caught (sometimes useful for debugging with FireBug). Defaults to 'false'. ### transparentEx > `Boolean transparentEx` > The sign whether the each tests in suite shouldn't catch any exceptions at all. Exceptions will be thrown "as is". This is also useful for debugging. Defaults to 'false' ### preload > `Array preload` > The array which contains the information about which files should be preloaded into each test's scope. The folloing rules applies during processing of the array: >1. If the string entry represent a class name (for example : `Test.Run.Test`) it is converting to the url, like "../lib/Test/Run/Test.js" >2. All string entries starting with 'jsan:' are replaced with the link to corresponding JSAN module. For example: jsan:Task.Joose.Core >3. If the entry ends with ".js", its supposed to be the url and is passing without modifications. >4. If the entry is an Object with `text` property, then the value of that property will be evaluted in the test's global scope directly. In this way you can run arbitrary code for setup. ### runCore > `String runCore` > Either `parallel` or `sequential`. Indicates how the individual tests should be run - several at once or one-by-one. ### maxThreads > `Number maxThreads` > The maximum number of tests running at the same time. Only applicable for `parallel` run-core. ### testClass > `Class testClass` > The test class which will be used for running tests, defaults to [Test.Run.Test]. SEE ALSO ======== General documentation for Joose: <http://openjsan.org/go/?l=Joose> BUGS ==== All complex software has bugs lurking in it, and this module is no exception. Please report any bugs through the web interface at <http://github.com/SamuraiJack/test.run/issues> AUTHORS ======= Nickolay Platonov [nplatonov@cpan.org](mailto:nplatonov@cpan.org) COPYRIGHT AND LICENSE ===================== Copyright (c) 2010, Nickolay Platonov All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Nickolay Platonov nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [Test.Run.Harness.Browser.Multi]: Harness/Browser/Multi.html [Test.Run.Test]: Test.html */