Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9c9e4b
commit 328a327
Showing
1 changed file
with
29 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`); | ||
} |