-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-jsdom.js
46 lines (34 loc) · 1.02 KB
/
test-jsdom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var jsdom = require('jsdom');
var fs = require('fs');
var async = require('async');
var file = fs.readFileSync('./test.html').toString();
var count = 0;
async.whilst(
function () {
return count < 2000;
},
function (callback) {
count++;
jsdom.env({
html: file,
done: function(error, window) {
// Usage.
console.log('test:', window.document.querySelectorAll('p').length);
// Log mem.
var mem = process.memoryUsage().heapUsed;
console.log(count + ')', Math.round(mem / 1000000) +' MB', '('+mem+')');
// Free mem.
window.close();
if (!global.gc) {
console.error('Use "node --expose-gc script.js" to test with gc.')
return;
} else {
global.gc();
}
setTimeout(callback, 1000);
}
});
},
function (err) {
}
);