2019-10-04 20:58:44 +00:00
|
|
|
const { ipcRenderer } = require('electron');
|
2018-09-18 18:00:31 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = require('chai');
|
2017-05-04 17:49:01 +00:00
|
|
|
|
2017-10-27 00:53:47 +00:00
|
|
|
describe('process module', () => {
|
2018-08-10 14:03:30 +00:00
|
|
|
describe('process.getCreationTime()', () => {
|
|
|
|
it('returns a creation time', () => {
|
|
|
|
const creationTime = process.getCreationTime();
|
|
|
|
expect(creationTime).to.be.a('number').and.be.at.least(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-27 00:53:47 +00:00
|
|
|
describe('process.getCPUUsage()', () => {
|
|
|
|
it('returns a cpu usage object', () => {
|
2017-05-04 21:15:27 +00:00
|
|
|
const cpuUsage = process.getCPUUsage();
|
2018-08-03 19:07:27 +00:00
|
|
|
expect(cpuUsage.percentCPUUsage).to.be.a('number');
|
|
|
|
expect(cpuUsage.idleWakeupsPerSecond).to.be.a('number');
|
2017-05-04 17:49:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-27 00:53:47 +00:00
|
|
|
describe('process.getIOCounters()', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
this.skip();
|
|
|
|
}
|
|
|
|
});
|
2017-10-27 00:53:47 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
it('returns an io counters object', () => {
|
2017-05-04 21:15:27 +00:00
|
|
|
const ioCounters = process.getIOCounters();
|
2018-08-03 19:07:27 +00:00
|
|
|
expect(ioCounters.readOperationCount).to.be.a('number');
|
|
|
|
expect(ioCounters.writeOperationCount).to.be.a('number');
|
|
|
|
expect(ioCounters.otherOperationCount).to.be.a('number');
|
|
|
|
expect(ioCounters.readTransferCount).to.be.a('number');
|
|
|
|
expect(ioCounters.writeTransferCount).to.be.a('number');
|
|
|
|
expect(ioCounters.otherTransferCount).to.be.a('number');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-30 09:50:35 +00:00
|
|
|
describe('process.getBlinkMemoryInfo()', () => {
|
|
|
|
it('returns blink memory information object', () => {
|
|
|
|
const heapStats = process.getBlinkMemoryInfo();
|
|
|
|
expect(heapStats.allocated).to.be.a('number');
|
|
|
|
expect(heapStats.total).to.be.a('number');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-28 08:57:53 +00:00
|
|
|
describe('process.getProcessMemoryInfo()', async () => {
|
|
|
|
it('resolves promise successfully with valid data', async () => {
|
|
|
|
const memoryInfo = await process.getProcessMemoryInfo();
|
|
|
|
expect(memoryInfo).to.be.an('object');
|
|
|
|
if (process.platform === 'linux' || process.platform === 'windows') {
|
|
|
|
expect(memoryInfo.residentSet).to.be.a('number').greaterThan(0);
|
|
|
|
}
|
|
|
|
expect(memoryInfo.private).to.be.a('number').greaterThan(0);
|
|
|
|
// Shared bytes can be zero
|
|
|
|
expect(memoryInfo.shared).to.be.a('number').greaterThan(-1);
|
|
|
|
});
|
|
|
|
});
|
2018-08-03 19:07:27 +00:00
|
|
|
|
|
|
|
describe('process.getSystemMemoryInfo()', () => {
|
|
|
|
it('returns system memory info object', () => {
|
|
|
|
const systemMemoryInfo = process.getSystemMemoryInfo();
|
|
|
|
expect(systemMemoryInfo.free).to.be.a('number');
|
|
|
|
expect(systemMemoryInfo.total).to.be.a('number');
|
2017-05-04 17:49:01 +00:00
|
|
|
});
|
|
|
|
});
|
2018-06-10 12:00:36 +00:00
|
|
|
|
2019-02-18 12:59:48 +00:00
|
|
|
describe('process.getSystemVersion()', () => {
|
|
|
|
it('returns a string', () => {
|
|
|
|
expect(process.getSystemVersion()).to.be.a('string');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-10 12:00:36 +00:00
|
|
|
describe('process.getHeapStatistics()', () => {
|
|
|
|
it('returns heap statistics object', () => {
|
|
|
|
const heapStats = process.getHeapStatistics();
|
2018-08-03 19:07:27 +00:00
|
|
|
expect(heapStats.totalHeapSize).to.be.a('number');
|
|
|
|
expect(heapStats.totalHeapSizeExecutable).to.be.a('number');
|
|
|
|
expect(heapStats.totalPhysicalSize).to.be.a('number');
|
|
|
|
expect(heapStats.totalAvailableSize).to.be.a('number');
|
|
|
|
expect(heapStats.usedHeapSize).to.be.a('number');
|
|
|
|
expect(heapStats.heapSizeLimit).to.be.a('number');
|
|
|
|
expect(heapStats.mallocedMemory).to.be.a('number');
|
|
|
|
expect(heapStats.peakMallocedMemory).to.be.a('number');
|
|
|
|
expect(heapStats.doesZapGarbage).to.be.a('boolean');
|
2018-06-10 12:00:36 +00:00
|
|
|
});
|
|
|
|
});
|
2018-09-18 18:00:31 +00:00
|
|
|
|
|
|
|
describe('process.takeHeapSnapshot()', () => {
|
2019-10-04 20:58:44 +00:00
|
|
|
it('returns true on success', async () => {
|
|
|
|
const filePath = path.join(await ipcRenderer.invoke('get-temp-dir'), 'test.heapsnapshot');
|
2018-09-18 18:00:31 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
2021-03-17 18:23:03 +00:00
|
|
|
|
|
|
|
describe('process.contextId', () => {
|
|
|
|
it('is a string', () => {
|
|
|
|
expect(process.contextId).to.be.a('string');
|
|
|
|
});
|
|
|
|
});
|
2017-05-04 17:49:01 +00:00
|
|
|
});
|