jsdom: Run a page's javascript functions [duplicate]


I've been messing around with jsdom and I can't figure out how to run functions from the html page. For example, I've got a simple page like this:

<html>
  <body>
    Hello
  </body>
  <script>
    function test() {
      document.write("Bye bye")
    }
  </script>
</html>

And I'd like to execute the test function from jsdom. How do I go about doing this? I've tried simply calling the function, but node complains that it doesn't exist.

jsdom.env({
    url : "http://localhost:8000/test.html",
    features : {
        FetchExternalResources : ['script'],
        ProcessExternalResources : ['script']
    },
    done : function (error, window) {
        test(); // I'd like to do something like this.
        console.log(window.document.innerHTML);
    }
});

Well apparently the correct way to do this is with window.test(), and the appropriate features:

jsdom.env({
    url : "http://localhost:8000/test.html",
    features : {
        FetchExternalResources : ['script'],
        ProcessExternalResources : ['script']
    },
    done : function (error, window) {
        window.test();
        console.log(window.document.innerHTML);
    }
});