// ========================================================================== // Project: SproutCore Costello - Property Observing Library // Copyright: ©2006-2010 Sprout Systems, Inc. and contributors. // Portions ©2008-2010 Apple Inc. All rights reserved. // License: Licensed under MIT license (see license.js) // ========================================================================== /*globals CoreTest Q$ */ sc_require('jquery'); /** @class A test plan contains a set of functions that will be executed in order. The results will be recorded into a results hash as well as calling a delegate. When you define tests and modules, you are adding to the active test plan. The test plan is then run when the page has finished loading. Normally you will not need to work with a test plan directly, though if you are writing a test runner application that needs to monitor test progress you may write a delegate to talk to the test plan. The CoreTest.Plan.fn hash contains functions that will be made global via wrapper methods. The methods must accept a Plan object as their first parameter. h2. Results The results hash contains a summary of the results of running the test plan. It includes the following properties: - *assertions* - the total number of assertions - *tests* - the total number of tests - *passed* - number of assertions that passed - *failed* - number of assertions that failed - *errors* - number of assertions with errors - *warnings* - number of assertions with warnings You can also consult the log property, which contains an array of hashes - one for each assertion - with the following properties: - *module* - module descriptions - *test* - test description - *message* - assertion description - *result* - CoreTest.OK, CoreTest.FAILED, CoreTest.ERROR, CoreTest.WARN @since SproutCore 1.0 */ CoreTest.Plan = { /** Define a new test plan instance. Optionally pass attributes to apply to the new plan object. Usually you will call this without arguments. @param {Hash} attrs plan arguments @returns {CoreTest.Plan} new instance/subclass */ create: function(attrs) { var len = arguments.length, ret = CoreTest.beget(this), idx; for(idx=0;idx 250) { this.pause(); this.pauseTime = now ; } } }); }, /** Converts the passed string into HTML and then appends it to the main body element. This is a useful way to automatically load fixture HTML into the main page. */ htmlbody: function htmlbody(string) { this.synchronize(function() { var html = Q$(string) ; var body = Q$('body')[0]; // first, find the first element with id 'htmlbody-begin' if exists, // remove everything after that to reset... var begin = Q$('body #htmlbody-begin')[0]; if (!begin) { begin = Q$('
')[0]; body.appendChild(begin); } else { while(begin.nextSibling) body.removeChild(begin.nextSibling); } begin = null; // now append new content html.each(function() { body.appendChild(this); }); }) ; }, /** Records the results of a test. This will add the results to the log and notify the delegate. The passed assertions array should contain hashes with the result and message. */ record: function(module, test, assertions, timings) { var r = this.results, len = assertions.length, del = this.delegate, idx, cur; r.tests++; for(idx=0;idx