<commit_before>
describe("oboe integration (real http)", function(){

   it('gets all expected callbacks by time request finishes',  function() {
       
      var asserter = givenAnOboeInstance('/testServer/tenSlowNumbers')
         .andWeAreListeningForNodes('![*]');         
      
      waitsFor( asserter.toComplete(), 'the request to complete', ASYNC_TEST_TIMEOUT);

      runs(function(){
               
         asserter.thenTheInstance(
             matched(0).atPath([0])
         ,   matched(1).atPath([1])
         ,   matched(2).atPath([2])
         ,   matched(3).atPath([3])
         ,   matched(4).atPath([4])
         ,   matched(5).atPath([5])
         ,   matched(6).atPath([6])
         ,   matched(7).atPath([7])
         ,   matched(8).atPath([8])
         ,   matched(9).atPath([9])
         );        
      });
   })
   
   it('can abort once some data has been found in streamed response',  function() {
       
      var aborted = false; 
       
      var asserter = givenAnOboeInstance('/testServer/tenSlowNumbers')
         .andWeAreListeningForNodes('![5]', function(){
             asserter.andWeAbortTheRequest();
             aborted = true;
          });         
      
      waitsFor( function(){return aborted}, 'the request to be aborted', ASYNC_TEST_TIMEOUT);
      
      // in case we didn't abort, wait a little longer. If we didn't really abort we'd get the
      // rest of the data now and the test would fail:
      waitsFor( someSecondsToPass(3), ASYNC_TEST_TIMEOUT);      

      runs( function(){
         asserter.thenTheInstance(
            // because the request was aborted on index array 5, we got 6 numbers (inc zero)
            // not the whole ten.
            hasRootJson([0,1,2,3,4,5])
         );
      });
   })
   
   it('can abort once some data has been found in not very streamed response',  function() {
       
      // like above but we're getting a static file not the streamed numbers. This means
      // we'll almost certainly read in the whole response as one onprogress it is on localhost
      // and the json is very small 

      var aborted = false; 
       
      var asserter = givenAnOboeInstance('/testServer/static/json/firstTenNaturalNumbers.json')
         .andWeAreListeningForNodes('![5]', function(){
             asserter.andWeAbortTheRequest();
             aborted = true;
          });         
      
      waitsFor( function(){return aborted}, 'the request to be aborted', ASYNC_TEST_TIMEOUT);
      
      // in case we didn't abort, wait a little longer. If we didn't really abort we'd get the
      // rest of the data now and the test would fail:
      waitsFor( someSecondsToPass(1), ASYNC_TEST_TIMEOUT);      

      runs( function(){
         asserter.thenTheInstance(
            // because the request was aborted on index array 5, we got 6 numbers (inc zero)
            // not the whole ten.
            hasRootJson([0,1,2,3,4,5])
         );
      });
   })      
   
   it('gives full json to callback when request finishes',  function( queue ) {
            
      var fullResponse = null;            
                           
      oboe.doGet(                      
         '/testServer/static/json/firstTenNaturalNumbers.json',
         
         function ajaxFinished(obj) {                              
            fullResponse = obj;               
         }
      );   
      
      waitsFor( function(){ return !!fullResponse }, 'the request to complete', ASYNC_TEST_TIMEOUT )
      
      runs( function(){
         expect(fullResponse).toEqual([0,1,2,3,4,5,6,7,8,9])
      });      
   })
      
   function someSecondsToPass(waitSecs) {
      
      function now(){
         // IE8 doesn't have Date.now() 
         return new Date().getTime();
      }
      
      var waitStart = now(),
          waitMs = waitSecs * 1000;
      
      return function(){
         return now() > (waitStart + waitMs); 
      }<commit_msg>fully end-to-end test for headers<commit_after>
describe("oboe integration (real http)", function(){

   it('gets all expected callbacks by time request finishes',  function() {
       
      var asserter = givenAnOboeInstance('/testServer/tenSlowNumbers')
         .andWeAreListeningForNodes('![*]');         
      
      waitsFor( asserter.toComplete(), 'the request to complete', ASYNC_TEST_TIMEOUT);

      runs(function(){
               
         asserter.thenTheInstance(
             matched(0).atPath([0])
         ,   matched(1).atPath([1])
         ,   matched(2).atPath([2])
         ,   matched(3).atPath([3])
         ,   matched(4).atPath([4])
         ,   matched(5).atPath([5])
         ,   matched(6).atPath([6])
         ,   matched(7).atPath([7])
         ,   matched(8).atPath([8])
         ,   matched(9).atPath([9])
         );        
      });
   })
   
   it('can abort once some data has been found in streamed response',  function() {
       
      var aborted = false; 
       
      var asserter = givenAnOboeInstance('/testServer/tenSlowNumbers')
         .andWeAreListeningForNodes('![5]', function(){
             asserter.andWeAbortTheRequest();
             aborted = true;
          });         
      
      waitsFor( function(){return aborted}, 'the request to be aborted', ASYNC_TEST_TIMEOUT);
      
      // in case we didn't abort, wait a little longer. If we didn't really abort we'd get the
      // rest of the data now and the test would fail:
      waitsFor( someSecondsToPass(3), ASYNC_TEST_TIMEOUT);      

      runs( function(){
         asserter.thenTheInstance(
            // because the request was aborted on index array 5, we got 6 numbers (inc zero)
            // not the whole ten.
            hasRootJson([0,1,2,3,4,5])
         );
      });
   })
   
   it('can abort once some data has been found in not very streamed response',  function() {
       
      // like above but we're getting a static file not the streamed numbers. This means
      // we'll almost certainly read in the whole response as one onprogress it is on localhost
      // and the json is very small 

      var aborted = false; 
       
      var asserter = givenAnOboeInstance('/testServer/static/json/firstTenNaturalNumbers.json')
         .andWeAreListeningForNodes('![5]', function(){
             asserter.andWeAbortTheRequest();
             aborted = true;
          });         
      
      waitsFor( function(){return aborted}, 'the request to be aborted', ASYNC_TEST_TIMEOUT);
      
      // in case we didn't abort, wait a little longer. If we didn't really abort we'd get the
      // rest of the data now and the test would fail:
      waitsFor( someSecondsToPass(1), ASYNC_TEST_TIMEOUT);      

      runs( function(){
         asserter.thenTheInstance(
            // because the request was aborted on index array 5, we got 6 numbers (inc zero)
            // not the whole ten.
            hasRootJson([0,1,2,3,4,5])
         );
      });
   })      
   
   it('gives full json to callback when request finishes',  function( queue ) {
            
      var fullResponse = null;            
                           
      oboe.doGet(                      
         '/testServer/static/json/firstTenNaturalNumbers.json',
         
         function ajaxFinished(obj) {                              
            fullResponse = obj;               
         }
      );   
      
      waitsFor( function(){ return !!fullResponse }, 'the request to complete', ASYNC_TEST_TIMEOUT )
      
      runs( function(){
         expect(fullResponse).toEqual([0,1,2,3,4,5,6,7,8,9])
      });      
   })
   
   it('gives header to server side',  function( queue ) {

      var done = false;

      oboe.doGet(                      
         {  url: '/testServer/echoBackHeaders',
            headers: {'SNARFU':'SNARF'},
            complete:   function ajaxFinished() {                              
                           done = true;               
                        }
         }
      ).onNode( 'SNARFU', function( headerValue ){
         expect( headerValue ).toBe( 'SNARF' )
      })   
      
      waitsFor( function(){ return done }, 'the request to complete', ASYNC_TEST_TIMEOUT )            
   })
      
   function someSecondsToPass(waitSecs) {
      
      function now(){
         // IE8 doesn't have Date.now() 
         return new Date().getTime();
      }
      
      var waitStart = now(),
          waitMs = waitSecs * 1000;
      
      return function(){
         return now() > (waitStart + waitMs); 
      }
{'fraction_non_alphanumeric': 0.11020025764141, 'fraction_numerical': 0.012882070500058554, 'mean_word_length': 1.7042431918936036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991661', 'n_tokens_mistral': 2446, 'n_tokens_neox': 2377, 'n_words': 639}