feat: add process.takeHeapSnapshot() / webContents.takeHeapSnapshot() (#14456)

This commit is contained in:
Milan Burda 2018-09-18 20:00:31 +02:00 committed by Shelley Vohr
parent 1855144d26
commit e22142ef9c
17 changed files with 262 additions and 5 deletions

View file

@ -1,3 +1,7 @@
const { remote } = require('electron')
const fs = require('fs')
const path = require('path')
const { expect } = require('chai')
describe('process module', () => {
@ -67,4 +71,32 @@ describe('process module', () => {
expect(heapStats.doesZapGarbage).to.be.a('boolean')
})
})
describe('process.takeHeapSnapshot()', () => {
it('returns true on success', () => {
const filePath = path.join(remote.app.getPath('temp'), 'test.heapsnapshot')
const cleanup = () => {
try {
fs.unlinkSync(filePath)
} catch (e) {
// ignore error
}
}
try {
const success = process.takeHeapSnapshot(filePath)
expect(success).to.be.true()
const stats = fs.statSync(filePath)
expect(stats.size).not.to.be.equal(0)
} finally {
cleanup()
}
})
it('returns false on failure', () => {
const success = process.takeHeapSnapshot('')
expect(success).to.be.false()
})
})
})