Skip to content

Instantly share code, notes, and snippets.

@cdent
Last active December 16, 2015 15:59
Show Gist options
  • Save cdent/5459753 to your computer and use it in GitHub Desktop.
Save cdent/5459753 to your computer and use it in GitHub Desktop.
demonstrate bug with jsdom and jsquery. 1382 value may need to be tweaked to tickle bug.
{
"name": "test",
"version": "0.0.1",
"dependencies": {
"jsdom": "*",
"jquery": "*"
}
}
var jsdom = require('jsdom'),
jquery = require('jquery'),
Emitter = require('events').EventEmitter;
function setupAction(id) {
var emitter = new Emitter();
console.log('setting up', id);
return {
emitter: emitter,
act1: function() {
var window = jsdom.jsdom().createWindow(),
jQuery = jquery.create(window);
setTimeout(function() {
emitter.emit('output', id);
window.close();
}, Math.floor(Math.random() * 10));
},
act2: function() {
setTimeout(function() {
emitter.emit('output', id);
}, Math.floor(Math.random() * 10));
}
};
}
var id = 1;
function build() {
var output = setupAction(id++);
output.emitter.on('output', function(data) {
console.log('got', data);
});
output.act1();
if (id < 1382) {
setTimeout(build, Math.floor(Math.random() * 1));
} else {
return;
}
}
build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment