File size: 1,144 Bytes
cf0f72e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | define([
'dojo/aspect',
'../../main',
'../Suite',
'../Test'
], function (aspect, main, Suite, Test) {
var currentSuite,
suites = [];
function registerSuite(name, factory) {
var parentSuite = currentSuite;
currentSuite = new Suite({ name: name, parent: parentSuite });
parentSuite.tests.push(currentSuite);
suites.push(parentSuite);
factory();
currentSuite = suites.pop();
}
return {
suite: function (name, factory) {
if (/* is a root suite */ !currentSuite) {
main.suites.forEach(function (suite) {
currentSuite = suite;
registerSuite(name, factory);
currentSuite = null;
});
}
else {
registerSuite(name, factory);
}
},
test: function (name, test) {
currentSuite.tests.push(new Test({ name: name, test: test, parent: currentSuite }));
},
before: function (fn) {
aspect.after(currentSuite, 'setup', fn);
},
after: function (fn) {
aspect.after(currentSuite, 'teardown', fn);
},
beforeEach: function (fn) {
aspect.after(currentSuite, 'beforeEach', fn);
},
afterEach: function (fn) {
aspect.after(currentSuite, 'afterEach', fn);
}
};
});
|