partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

TestRunner.js (1014B)


      1 /**
      2  * Implements a sequential test runner, which waits for previous tests to complete.
      3  * 
      4  * This is used with asynchronous tests.
      5  */
      6 Ext.define('PartKeeprSetup.TestRunner', {
      7 	extend: 'Ext.util.Observable',
      8 	
      9 	/**
     10 	 * Initialize the component
     11 	 */
     12 	initComponent: function () {
     13 		this.callParent();
     14 	},
     15 	/**
     16 	 * Runs the given tests. Each test must fire the "complete" event in
     17 	 * order to be runable.
     18 	 * 
     19 	 * @param tests An array of tests
     20 	 */
     21 	run: function (tests, callback) {
     22 		test = tests.shift();
     23 		this.tests = tests;
     24 		
     25 		if (!test) {
     26 			this.fireEvent("success");
     27 			return;
     28 		}
     29 		
     30 		test.callback = callback;
     31 		
     32 		/**
     33 		 * We re-assign the event handler on each cycle due to the asynchronous nature of the ajax requests.
     34 		 */
     35 		test.on("complete", this.onTestComplete, this);
     36 		test.run();
     37 	},
     38 	/**
     39 	 * Callback when the test is complete
     40 	 * @param test The test which was run
     41 	 */
     42 	onTestComplete: function (test) {
     43 		test.un(this.onTestComplete);
     44 		this.run(this.tests, test.callback);
     45 	}
     46 });