tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testharness-helpers.js (1207B)


      1 // Given an array of potentially asynchronous tests, this function will execute
      2 // each in serial, ensuring that one and only one test is executing at a time.
      3 //
      4 // The test array should look like this:
      5 //
      6 //
      7 //     var tests = [
      8 //       [
      9 //         "Test description goes here.",
     10 //         function () {
     11 //           // Test code goes here. `this` is bound to the test object.
     12 //         }
     13 //       ],
     14 //       ...
     15 //     ];
     16 //
     17 // The |setup| and |teardown| arguments are functions which are executed before
     18 // and after each test, respectively.
     19 function executeTestsSerially(testList, setup, teardown) {
     20  var tests = testList.map(function (t) {
     21    return {
     22      test: async_test(t[0]),
     23      code: t[1]
     24    };
     25  });
     26 
     27  var executeNextTest = function () {
     28    var current = tests.shift();
     29    if (current === undefined) {
     30      return;
     31    }
     32 
     33    // Setup the test fixtures.
     34    if (setup) {
     35      setup();
     36    }
     37 
     38    // Bind a callback to tear down the test fixtures.
     39    if (teardown) {
     40      current.test.add_cleanup(teardown);
     41    }
     42 
     43    // Execute the test.
     44    current.test.step(current.code);
     45  };
     46 
     47  add_result_callback(function () { setTimeout(executeNextTest, 0) });
     48  executeNextTest();
     49 }