Skip to content

Commit

Permalink
gah, try now
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 9, 2017
1 parent b9c9e4b commit 328a327
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions test/leak/test.js
@@ -1,27 +1,36 @@
const path = require('path')
const weak = require('weak')
const rollup = require('../..')

let shouldCollect = false;
let isCollected = false;
try {
const weak = require('weak')

const onCollect = () => isCollected = true;
let shouldCollect = false;
let isCollected = false;

let cache;
const run = () => rollup.rollup({
entry: path.resolve(__dirname, 'index.js'),
cache
}).then(bundle => {
weak(bundle, onCollect);
cache = bundle;
global.gc();
if (shouldCollect && !isCollected) {
throw new Error('Memory leak detected')
const onCollect = () => isCollected = true;

let cache;
const run = () => rollup.rollup({
entry: path.resolve(__dirname, 'index.js'),
cache
}).then(bundle => {
weak(bundle, onCollect);
cache = bundle;
global.gc();
if (shouldCollect && !isCollected) {
throw new Error('Memory leak detected')
}
shouldCollect = true;
})

run().then(run).then(() => console.log('Success')).catch((err) => {
console.error(err.message);
process.exit(1);
});
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err;
}
shouldCollect = true;
})

run().then(run).then(() => console.log('Success')).catch((err) => {
console.error(err.message);
process.exit(1);
});
console.log(`skipping memory leak test`);
}

0 comments on commit 328a327

Please sign in to comment.