Last active
March 31, 2016 15:24
-
-
Save tr4n2uil/48f52993f6da8f615007 to your computer and use it in GitHub Desktop.
Make functionalSuites in intern run in parallel. Just put this file alongside intern.js and replace "intern!object" in your functional test files with "tests/intern-parallel"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'intern!object', | |
'intern/chai!assert', | |
'require', | |
'intern/dojo/node!leadfoot/Command', | |
'intern/dojo/Promise', | |
'./intern' | |
], function (registerSuite, assert, require, Command, Promise, config, registry) { | |
var parallelRegister = function (descriptor) { | |
var test; | |
for (k in descriptor) { | |
test = descriptor[k]; | |
if (k === 'before') { | |
k = 'setup'; | |
} | |
if (k === 'after') { | |
k = 'teardown'; | |
} | |
switch (k) { | |
case 'name': | |
case 'timeout': | |
case 'setup': | |
case 'beforeEach': | |
case 'afterEach': | |
case 'teardown': | |
break; | |
default: | |
// TODO | |
if (typeof test !== 'function') { | |
//test.name = test.name || k; | |
descriptor.name = test.name || k; | |
descriptor[k] = parallelRegister(test); | |
} | |
else { | |
descriptor[k] = function(){ | |
var runTest = function(remote, resolve){ | |
var driver = test.apply({remote: remote}); | |
if(driver) driver.quit(); | |
resolve(remote); | |
} | |
var remote = this.remote; | |
return new Promise(function(resolve, reject){ | |
if(remote.done || false){ | |
session = remote.session; | |
for(var i in config.capabilities){ | |
session.capabilities[i] = config.capabilities[i]; | |
} | |
session.capabilities["name"] = descriptor.name || k; | |
session.server.createSession(session.capabilities).then(function(newSession){ | |
var remote = new Command(newSession) | |
runTest(remote, resolve); | |
}); | |
} | |
else { | |
remote.done = true; | |
runTest(remote, resolve); | |
} | |
}) | |
} | |
} | |
} | |
} | |
return descriptor; | |
}; | |
return function(descriptor){ | |
registerSuite(parallelRegister(descriptor)); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment