What is commonjs doing with the jquery package?

It seems global.window must exist at the point that jquery is required, this code also works.

var jsdom = require('jsdom');
global.document = jsdom.jsdom('<html></html>');
global.window = document.defaultView;

var jquery = require('jquery');
global.$ = jquery(window);