Created
September 28, 2012 21:31
-
-
Save fkowal/3802184 to your computer and use it in GitHub Desktop.
Yui JsTestDriver Adapter
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
var YUI_TESTS_TYPE = 'yui test case'; | |
TestCase('Yui Adapter Tests', null, YUI_TESTS_TYPE); | |
jstestdriver.pluginRegistrar.register({ | |
name: 'yui', | |
getTestRunsConfigurationFor: function (testCaseInfos, expressions, testRunsConfiguration) { | |
for (var i = 0; i < testCaseInfos.length; i++) { | |
if (testCaseInfos[i].getType() === YUI_TESTS_TYPE) { | |
testRunsConfiguration.push(new jstestdriver.TestRunConfiguration(testCaseInfos[i], [])); | |
} | |
} | |
return false; // allow other TestCases to be collected. | |
}, | |
runTestConfiguration: function (config, onTestDone, onComplete) { | |
if (config.getTestCaseInfo().getType() !== YUI_TESTS_TYPE) { | |
return false; | |
} | |
YUI({ | |
useBrowserConsole: true | |
}).use('*', function(Y) { | |
var runner = Y.Test.Runner, | |
start, elapsed, | |
runnerComplete = function() { | |
onComplete(); | |
}, | |
testDone = function(e) { | |
var messages = [], state = 'passed' | |
; | |
onTestDone( | |
new jstestdriver.TestResult( | |
e.testCase.name, | |
e.testName, | |
state, | |
jstestdriver.angular.toJson(messages), | |
'', // log | |
elapsed // time | |
) | |
); | |
}, | |
formatStack = function (stack) { | |
var line, lines = (stack || '').split(/\r?\n/), l = lines.length, frames = []; | |
for (var i = 0; i < l; i++) { | |
line = lines[i]; | |
if (line.match(/\/yuiadapter[\.-]/)) { | |
continue; | |
} | |
frames.push(line.replace(/https?:\/\/\w+(:\d+)?\/test\//, '').replace(/^\s*/, ' ')); | |
} | |
return frames.join('\n'); | |
}, | |
testError = function testError(e) { | |
var err = e.error, | |
stack = formatStack(err.getError().stack), | |
messages = [{name: e.error.name, message: e.error.getMessage(), stack: stack}], | |
state = e.error instanceof Y.Test.AssertionError ? 'failed' : 'error' | |
; | |
onTestDone( | |
new jstestdriver.TestResult( | |
e.testCase.name, | |
e.testName, | |
state, | |
jstestdriver.angular.toJson(messages), | |
'', // log | |
elapsed // time | |
) | |
); | |
}, | |
// measure execution time | |
begin = function (e) { | |
start = +new Date(); | |
}, | |
testComplete = function(e) { | |
elapsed = +new Date() - start; | |
}; | |
runner.subscribe(runner.TEST_CASE_BEGIN_EVENT, begin); | |
runner.subscribe(runner.TEST_CASE_COMPLETE_EVENT, testComplete); | |
// catch test events | |
runner.subscribe(runner.TEST_PASS_EVENT, testDone); | |
runner.subscribe(runner.TEST_FAIL_EVENT, testError); | |
//runner.subscribe(runner.TEST_IGNORE_EVENT, testIgnore); | |
// notify jstestdriver when finished | |
runner.subscribe(runner.COMPLETE_EVENT, runnerComplete); | |
runner.run(); // TODO in test executor ? | |
}); | |
return true; | |
}, | |
onTestsFinish: function () { | |
//jasmine.currentEnv_ = null; | |
//collectMode = true; | |
var x = '1'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment