|
| 1 | +import os from 'os'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { DiagnosticMain } from './diagnostic.main.runtime'; |
| 4 | + |
| 5 | +describe('DiagnosticMain', () => { |
| 6 | + describe('getBitVersion', () => { |
| 7 | + it('should return an object with a version string', () => { |
| 8 | + const result = DiagnosticMain.getBitVersion(); |
| 9 | + expect(result).to.have.property('version'); |
| 10 | + expect(result.version).to.be.a('string'); |
| 11 | + }); |
| 12 | + }); |
| 13 | + |
| 14 | + describe('getProcessInfo', () => { |
| 15 | + it('should return process uptime as a positive number', () => { |
| 16 | + const result = DiagnosticMain.getProcessInfo(); |
| 17 | + expect(result.uptime).to.be.a('number'); |
| 18 | + expect(result.uptime).to.be.greaterThan(0); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should return the current process pid', () => { |
| 22 | + const result = DiagnosticMain.getProcessInfo(); |
| 23 | + expect(result.pid).to.equal(process.pid); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should return node version, platform, and arch', () => { |
| 27 | + const result = DiagnosticMain.getProcessInfo(); |
| 28 | + expect(result.nodeVersion).to.equal(process.version); |
| 29 | + expect(result.platform).to.equal(process.platform); |
| 30 | + expect(result.arch).to.equal(process.arch); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should return memory usage with all expected fields', () => { |
| 34 | + const result = DiagnosticMain.getProcessInfo(); |
| 35 | + expect(result.memory).to.have.property('rss').that.is.a('number'); |
| 36 | + expect(result.memory).to.have.property('heapTotal').that.is.a('number'); |
| 37 | + expect(result.memory).to.have.property('heapUsed').that.is.a('number'); |
| 38 | + expect(result.memory).to.have.property('external').that.is.a('number'); |
| 39 | + expect(result.memory).to.have.property('arrayBuffers').that.is.a('number'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should return memory values that are positive', () => { |
| 43 | + const result = DiagnosticMain.getProcessInfo(); |
| 44 | + expect(result.memory.rss).to.be.greaterThan(0); |
| 45 | + expect(result.memory.heapTotal).to.be.greaterThan(0); |
| 46 | + expect(result.memory.heapUsed).to.be.greaterThan(0); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return cpu usage with user and system fields', () => { |
| 50 | + const result = DiagnosticMain.getProcessInfo(); |
| 51 | + expect(result.cpu).to.have.property('user').that.is.a('number'); |
| 52 | + expect(result.cpu).to.have.property('system').that.is.a('number'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should return system info matching os module values', () => { |
| 56 | + const result = DiagnosticMain.getProcessInfo(); |
| 57 | + expect(result.system.totalMemory).to.equal(os.totalmem()); |
| 58 | + expect(result.system.cpuCount).to.equal(os.cpus().length); |
| 59 | + expect(result.system.hostname).to.equal(os.hostname()); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should return load average as an array of 3 numbers', () => { |
| 63 | + const result = DiagnosticMain.getProcessInfo(); |
| 64 | + expect(result.system.loadAverage).to.be.an('array').with.lengthOf(3); |
| 65 | + result.system.loadAverage.forEach((val) => { |
| 66 | + expect(val).to.be.a('number'); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should return free memory less than or equal to total memory', () => { |
| 71 | + const result = DiagnosticMain.getProcessInfo(); |
| 72 | + expect(result.system.freeMemory).to.be.at.most(result.system.totalMemory); |
| 73 | + expect(result.system.freeMemory).to.be.greaterThan(0); |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments