1
/* Copyright (c) 2009, Canonical Ltd. All rights reserved. */
3
YUI.add("lazr.testing.runner", function(Y) {
12
Runner = Y.namespace("lazr.testing.Runner");
14
Runner.add = function(suite) {
15
if ((typeof jstestdriver === "undefined")) {
16
// If we are not running under JsTestDriver, then
17
// register the suite with Y.Test.Runner and run it.
18
Y.Test.Runner.add(suite);
20
// If ``jstestdriver`` is defined, that means we are
21
// running under JsTestDriver, so instead register each
22
// test case from the suite as a separate TestCase() with
26
Y.each(suite.items, function(testCase, idx) {
27
var suiteName = suite.name;
28
var testCaseName = testCase.name;
31
for (var prop in testCase){
32
// Clone everything that is not a test method.
33
if (prop.indexOf("test") === -1){
34
clone[prop] = testCase[prop];
38
// Now for each test method, create a JsTestDriver
39
// TestCase that wraps a single YUI TestSuite, that wraps
40
// a clone of the original TestCase but with only the
41
// single test method that we are interested in.
42
Y.each(testCase, function(property, name) {
43
if (name.indexOf("test") === 0 &&
44
Y.Lang.isFunction(property)){
45
tests.push({"suiteName": suiteName,
46
"caseName": testCaseName,
54
Y.each(tests, function(testObject, i) {
55
testObject = tests[i];
58
"setUp": Y.bind(function(testObject){
59
var testSuite = new Y.Test.Suite(testObject.suiteName);
60
var testCase = new Y.Test.Case(testObject['case']);
61
testCase[testObject.methodName] = testObject.method;
62
testSuite.add(testCase);
63
Y.Test.Runner.clear();
64
Y.Test.Runner.add(testSuite);
66
"tearDown": function(){
67
Y.Test.Runner.clear();
71
fakeTestCase[testObject.methodName] = Y.bind(function (testObject) {
74
var onComplete = function (methodName, results, e) {
75
Y.Test.Runner.unsubscribe("testcasecomplete");
76
results.push(e.results[methodName]);
79
Y.Test.Runner.subscribe(
81
Y.bind(onComplete, this, testObject.methodName, results),
88
if (!Y.Test.Runner.isRunning()){
94
var result = results.pop();
95
if (result === undefined) {
96
fail("Test did not finish after 100 iterations.");
98
if (result.result == "fail") {
103
}, this, testObject);
105
// JSLint will complain if the constructur is used without `new`
106
// and if the result of `new` is not used. The TestCase class is
107
// defined globally by jstestdriver and automatically registers
108
// itself, so it is not necessary to return this object.
109
var ignored = new TestCase(
110
testObject.caseName + "." + testObject.methodName,
116
Runner.run = function(suite) {
117
Y.on("domready", function() {
118
if ((typeof jstestdriver === "undefined")) {
119
// If we are not running under JsTestDriver, then run all
120
// the registered test suites with Y.Test.Runner.
121
var yconsole = new Y.Console({
123
useBrowserConsole: true
125
yconsole.render("#log");
131
}, "0.1", {"requires": ["oop", "test", "console"]});