|
10 | 10 | YTest = bender.Y.Test,
|
11 | 11 | i;
|
12 | 12 |
|
13 |
| - // override and extend assertions |
| 13 | + // Override and extend assertions. |
14 | 14 | window.assert = bender.assert;
|
15 | 15 | window.arrayAssert = bender.arrayAssert;
|
16 | 16 | window.objectAssert = bender.objectAssert;
|
17 | 17 |
|
18 |
| - // clean-up data from previous tests if available |
19 |
| - // TODO check if this could be deleted after separating test context from parent |
| 18 | + // Clean-up data from previous tests if available. |
| 19 | + // TODO check if this could be deleted after separating test context from parent. |
20 | 20 | if ( bender.editor ) {
|
21 | 21 | delete bender.editor;
|
22 | 22 | }
|
|
109 | 109 | };
|
110 | 110 |
|
111 | 111 | /**
|
112 |
| - * Asserts that HTML data are the same. Use {@link bender.tools.compatHtml} to sort attributes, fix styles and encode Nbsp. |
| 112 | + * Asserts that HTML data are the same. Use {@link bender.tools.compatHtml} to sort attributes, |
| 113 | + * fix styles and encode `nbsp`. |
113 | 114 | *
|
114 | 115 | * @param {String} expected
|
115 | 116 | * @param {String} actual
|
|
119 | 120 | assert.areSame( expected, bender.tools.compatHtml( actual, false, true, false, true, true ), message );
|
120 | 121 | };
|
121 | 122 |
|
122 |
| - // add support test ignore |
| 123 | + // Add support test ignore. |
123 | 124 | YUITest.Ignore = function() {};
|
124 | 125 |
|
125 | 126 | bender.assert.ignore = function() {
|
|
153 | 154 |
|
154 | 155 | if ( typeof test == 'string' ) {
|
155 | 156 | updateResult( node.parent, test );
|
156 |
| - // Ignore all tests in this whole test case |
| 157 | + // Ignore all tests in this whole test case. |
157 | 158 | } else {
|
158 | 159 | for ( name in test ) {
|
159 | 160 | if ( typeof test[ name ] == 'function' && name.match( /^test/ ) ) {
|
|
165 | 166 | };
|
166 | 167 |
|
167 | 168 | YTest.Runner._resumeTest = function( segment ) {
|
168 |
| - //get relevant information |
| 169 | + // Get relevant information. |
169 | 170 | var node = this._cur,
|
170 | 171 | failed = false,
|
171 | 172 | ignored = false,
|
172 | 173 | error = null,
|
173 | 174 | testName, testCase, shouldFail, shouldError;
|
174 | 175 |
|
175 |
| - //we know there's no more waiting now |
| 176 | + // We know there's no more waiting now. |
176 | 177 | this._waiting = false;
|
177 | 178 |
|
178 |
| - //if there's no node, it probably means a wait() was called after resume() |
| 179 | + // If there's no node, it probably means a wait() was called after resume(). |
179 | 180 | if ( !node ) {
|
180 | 181 | return;
|
181 | 182 | }
|
182 | 183 |
|
183 | 184 | testName = node.testObject;
|
184 | 185 | testCase = node.parent.testObject;
|
185 | 186 |
|
186 |
| - //cancel other waits if available |
| 187 | + // Cancel other waits if available. |
187 | 188 | if ( testCase.__yui_wait ) {
|
188 | 189 | clearTimeout( testCase.__yui_wait );
|
189 | 190 | delete testCase.__yui_wait;
|
190 | 191 | }
|
191 | 192 |
|
192 |
| - //get the "should" test cases |
| 193 | + // Get the "should" test cases. |
193 | 194 | shouldFail = testName.indexOf( 'fail:' ) === 0 ||
|
194 | 195 | ( testCase._should.fail || {} )[ testName ];
|
195 | 196 |
|
196 | 197 | shouldError = ( testCase._should.error || {} )[ testName ];
|
197 | 198 |
|
198 | 199 | this._inTest = true;
|
199 | 200 |
|
200 |
| - //try the test |
| 201 | + // Try the test. |
201 | 202 | try {
|
202 |
| - //run the test |
| 203 | + // Run the test. |
203 | 204 | segment.call( testCase, this._context );
|
204 | 205 |
|
205 |
| - //if the test hasn't already failed and doesn't have any asserts... |
| 206 | + // If the test hasn't already failed and doesn't have any asserts... |
206 | 207 | if ( !YUITest.Assert._getCount() && !this._ignoreEmpty ) {
|
207 | 208 | throw new YUITest.AssertionError( 'Test has no asserts.' );
|
208 |
| - //if it should fail, and it got here, then it's a fail because it didn't |
| 209 | + // If it should fail, and it got here, then it's a fail because it didn't. |
209 | 210 | } else if ( shouldFail ) {
|
210 | 211 | error = new YUITest.ShouldFail();
|
211 | 212 | failed = true;
|
|
214 | 215 | failed = true;
|
215 | 216 | }
|
216 | 217 | } catch ( thrown ) {
|
217 |
| - //cancel any pending waits, the test already failed |
| 218 | + // Cancel any pending waits, the test already failed. |
218 | 219 | if ( testCase.__yui_wait ) {
|
219 | 220 | clearTimeout( testCase.__yui_wait );
|
220 | 221 | delete testCase.__yui_wait;
|
|
231 | 232 | } else if ( thrown instanceof YUITest.Wait ) {
|
232 | 233 | if ( typeof thrown.segment == 'function' ) {
|
233 | 234 | if ( typeof thrown.delay == 'number' ) {
|
234 |
| - //some environments don't support setTimeout |
| 235 | + // Some environments don't support setTimeout. |
235 | 236 | if ( typeof setTimeout != 'undefined' ) {
|
236 | 237 | testCase.__yui_wait = setTimeout( function() {
|
237 | 238 | YUITest.TestRunner._resumeTest( thrown.segment );
|
|
246 | 247 |
|
247 | 248 | return;
|
248 | 249 | } else {
|
249 |
| - //first check to see if it should error |
| 250 | + // First check to see if it should error. |
250 | 251 | if ( !shouldError ) {
|
251 | 252 | error = new YUITest.UnexpectedError( thrown );
|
252 | 253 | failed = true;
|
|
270 | 271 | this._inTest = false;
|
271 | 272 |
|
272 | 273 | if ( !ignored ) {
|
273 |
| - //fire appropriate event |
| 274 | + // Fire appropriate event. |
274 | 275 | this.fire( {
|
275 | 276 | type: failed ? this.TEST_FAIL_EVENT : this.TEST_PASS_EVENT,
|
276 | 277 | testCase: testCase,
|
277 | 278 | testName: testName,
|
278 | 279 | error: failed ? error : undefined
|
279 | 280 | } );
|
280 | 281 |
|
281 |
| - //run the tear down |
| 282 | + // Run the tear down. |
282 | 283 | this._execNonTestMethod( node.parent, 'tearDown', false );
|
283 | 284 |
|
284 |
| - //reset the assert count |
| 285 | + // Reset the assert count. |
285 | 286 | YUITest.Assert._reset();
|
286 | 287 |
|
287 |
| - //update results |
| 288 | + // Update results. |
288 | 289 | node.parent.results[ testName ] = {
|
289 | 290 | result: failed ? 'fail' : 'pass',
|
290 | 291 | message: error ? error.getMessage() : 'Test passed',
|
|
302 | 303 | node.parent.results.total++;
|
303 | 304 | }
|
304 | 305 |
|
305 |
| - //set timeout not supported in all environments |
| 306 | + // Set timeout not supported in all environments. |
306 | 307 | if ( typeof setTimeout != 'undefined' ) {
|
307 | 308 | setTimeout( function() {
|
308 | 309 | YUITest.TestRunner._run();
|
|
397 | 398 |
|
398 | 399 | if ( bender.plugins ) {
|
399 | 400 | toLoad++;
|
400 |
| - bender.deferred = true; |
| 401 | + defer(); |
401 | 402 |
|
402 | 403 | CKEDITOR.plugins.load( config.plugins, onLoad );
|
403 | 404 | }
|
|
408 | 409 | }
|
409 | 410 |
|
410 | 411 | toLoad++;
|
411 |
| - bender.deferred = true; |
| 412 | + defer(); |
412 | 413 |
|
413 | 414 | CKEDITOR.scriptLoader.load( config.adapters, onLoad );
|
414 | 415 | }
|
|
419 | 420 | }
|
420 | 421 |
|
421 | 422 | if ( !toLoad ) {
|
422 |
| - if ( bender.deferred ) { |
423 |
| - delete bender.deferred; |
424 |
| - } |
425 |
| - |
426 |
| - bender.startRunner(); |
| 423 | + startRunner(); |
427 | 424 | }
|
428 | 425 | }
|
429 | 426 | };
|
430 | 427 |
|
431 |
| - // keep reference to adapter's test function |
432 |
| - bender.orgTest = bender.test; |
| 428 | + var unlock, deferredTests; |
433 | 429 |
|
434 |
| - bender.test = function( tests ) { |
435 |
| - if ( bender.deferred ) { |
436 |
| - delete bender.deferred; |
| 430 | + // Defers Bender's startup. |
| 431 | + function defer() { |
| 432 | + if ( !unlock ) { |
| 433 | + unlock = bender.defer(); |
| 434 | + } |
| 435 | + } |
| 436 | + |
| 437 | + // Keep a reference to the original bender.test function. |
| 438 | + var orgTest = bender.test; |
| 439 | + |
| 440 | + // Flag saying if we need to restart the tests, e.g. when bender.test was executed asynchronously. |
| 441 | + var restart = false; |
437 | 442 |
|
438 |
| - bender.deferredTests = tests; |
| 443 | + bender.test = function( tests ) { |
| 444 | + if ( unlock && !restart ) { |
| 445 | + deferredTests = tests; |
439 | 446 | } else {
|
440 |
| - bender.startRunner( tests ); |
| 447 | + startRunner( tests ); |
441 | 448 | }
|
442 | 449 | };
|
443 | 450 |
|
444 |
| - bender.startRunner = function( tests ) { |
445 |
| - tests = tests || bender.deferredTests; |
446 |
| - |
447 |
| - if ( bender.deferredTests ) { |
448 |
| - delete bender.deferredTests; |
449 |
| - } |
| 451 | + function startRunner( tests ) { |
| 452 | + tests = tests || deferredTests; |
450 | 453 |
|
| 454 | + // startRunner was executed but there were no tests available yet. |
451 | 455 | if ( !tests ) {
|
| 456 | + restart = true; |
452 | 457 | return;
|
453 | 458 | }
|
454 | 459 |
|
|
477 | 482 | }
|
478 | 483 | }
|
479 | 484 |
|
480 |
| - bender.orgTest( tests ); |
| 485 | + // Run the original bender.test function. |
| 486 | + orgTest( tests ); |
481 | 487 |
|
482 |
| - // async:init stage 1: set up bender.editor |
| 488 | + // Unlock Bender startup. |
| 489 | + if ( unlock ) { |
| 490 | + unlock(); |
| 491 | + } |
| 492 | + |
| 493 | + // async:init stage 1: set up bender.editor. |
483 | 494 | function setUpEditor() {
|
484 | 495 | if ( !bender.editor ) {
|
485 | 496 | // If there is no bender.editor jump to stage 2.
|
|
494 | 505 | } );
|
495 | 506 | }
|
496 | 507 |
|
497 |
| - // async:init stage 2: set up bender.editors |
| 508 | + // async:init stage 2: set up bender.editors. |
498 | 509 | function setUpEditors() {
|
499 | 510 | if ( !bender.editors ) {
|
500 | 511 | // If there is no bender.editor jump to stage 3.
|
|
544 | 555 | }
|
545 | 556 | }
|
546 | 557 |
|
547 |
| - // async:init stage 3: call original async/async:init and finish async:init (testCase.callback). |
| 558 | + // async:init stage 3: call original async/async:init and finish async:init (testCase.callback). |
548 | 559 | function callback() {
|
549 | 560 | if ( bender._init ) {
|
550 | 561 | var init = bender._init;
|
|
565 | 576 | }
|
566 | 577 | }
|
567 | 578 | }
|
568 |
| - }; |
| 579 | + } |
569 | 580 |
|
570 | 581 | function onDocumentReady( callback ) {
|
571 | 582 | function complete() {
|
|
620 | 631 | };
|
621 | 632 | } )( this, bender );
|
622 | 633 |
|
623 |
| -// workaround for IE8 - window.resume / window.wait won't work in this environment... |
| 634 | +// Workaround for IE8 - window.resume / window.wait won't work in this environment... |
624 | 635 | var resume = bender.Y.Test.Case.prototype.resume = ( function() { // jshint ignore:line
|
625 | 636 | var org = bender.Y.Test.Case.prototype.resume;
|
626 | 637 |
|
|
0 commit comments