title: jsdom and $(document).ready
body: <p>I looks like when I run a page through <code>jsdom</code>, the <code>$(document).ready</code> block in the page script isn't being executed.</p>
  
  <p>Here is the html:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
    If everything works, you should see a message here:  &lt;h2 id="msg"&gt;&lt;/h2&gt;
  
    &lt;script&gt;
      var checkpoint1 = true
      var checkpoint2 = false
      $(document).ready(function(){
        checkpoint2 = true
        $('#msg').html("It works, it works, it works!")
      })
    &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and the codez:</p>
  
  <pre><code>fs = require('fs');
  htmlSource = fs.readFileSync("public/examples/test_js_dom.html", "utf8");
  
  global.jsdom = require("jsdom");
  
  jsdom.defaultDocumentFeatures = {
    FetchExternalResources   : ['script'],
    ProcessExternalResources : ['script'],
    MutationEvents           : '2.0',
    QuerySelector            : false
  };
  
  doc = jsdom.jsdom(htmlSource)
  window = doc.createWindow()
  jsdom.jQueryify(window, "http://code.jquery.com/jquery-1.8.3.min.js", function(){
    console.log(window.checkpoint1);
    console.log(window.checkpoint2);
    console.log(window.$().jquery)
    console.log("body:");
    console.log(window.$('body').html());
  });
  </code></pre>
  
  <p>and the output:</p>
  
  <pre><code>Bee@cleanroom:~/projects/notjs$ test/jsdom.js
  true
  false   
  1.8.3
  body:
  
        If everything works, you should see a message here:  &lt;h2 id="msg"&gt;&lt;/h2&gt;
  
        &lt;script&gt;
          var checkpoint1 = true
          var checkpoint2 = false
          $(document).ready(function(){
            checkpoint2 = true
            $('#msg').html("It works, it works, it works!")
          })
        &lt;/script&gt;
      &lt;script class="jsdom" src="http://code.jquery.com/jquery-1.8.3.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>adding detail to satisfied absurd stackoverflow ratio.</p>
  
  <pre><code>Bee@cleanroom:~/projects/notjs$ npm ls jsdom
  notjs@1.0.0 /Users/Bee/projects/notjs
  ├─┬ jquery@1.8.3
  │ └── jsdom@0.2.19
  └── jsdom@0.3.3
  Bee@cleanroom:~/projects/notjs$ node -v
  v0.8.15
  Bee@cleanroom:~/projects/notjs$ npm -v
  1.1.66
  </code></pre>
  
  <p>[SOLUTION]:   </p>
  
  <p>Thank you Dave for leading me to the right answer.   </p>
  
  <p>I think the complete jsdom answer goes like this; don't use jsdom.jQuerify, add the script tag to load jQuery in the page above the in page script (as it would need to in order to load the page in a browser).  </p>
  
  <p>html:</p>
  
  <pre><code>    ...
      If everything works, you should see a message here:  &lt;h2 id="msg"&gt;&lt;/h2&gt;
  
      &lt;script src="http://notjs.org/vendor/jquery-1.8.3.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
        var checkpoint1 = true
        var checkpoint2 = false
        $(document).ready(function(){
          var checkpoint2 = true
      ...       
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>    ...
      doc = jsdom.jsdom(htmlSource)
      window = doc.createWindow()
      window.addEventListener('load',  function(){
        console.log(window.checkpoint1);
        console.log(window.checkpoint2);
        console.log(window.$().jquery)
        console.log("body:");
        console.log(window.$('body').html());
      });
      ...
  </code></pre>