Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Make tests asynchronous, update types
Browse files Browse the repository at this point in the history
  • Loading branch information
Noel committed Mar 31, 2020
1 parent 0006075 commit 7923a22
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
8 changes: 7 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ declare module '@augu/sysinfo' {
cpu: string;
}

interface WindowsProcess {
name: string;
ppid: number;
pid: number;
}

interface UnixUptimeStats {
uptime: string;
users: number;
Expand Down Expand Up @@ -159,7 +165,7 @@ declare module '@augu/sysinfo' {
* @works Windows, Linux, MacOS
* @returns An array of all the processes running by the `pid` argument
*/
export function getProcesses(pid?: number): Process[];
export function getProcesses(pid?: number): (Process | WindowsProcess)[];

/**
* Gets information from the `uptime` command in Unix-subsystems
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ module.exports = {
*
* @param {number} pid The number of processes to list
* @works Windows, Linux, MacOS
* @returns An array of all the processes running by the `pid` argument
* @returns An array of all the processes that are sliced by the `pid` argument
*/
async getProcesses(pid = 10) {
if (this.getPlatform() === 'Windows') {
Expand Down
45 changes: 27 additions & 18 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@
const { inspect } = require('util');
const sys = require('../lib');

console.log(`@augu/sysinfo version: ${sys.version}`);
console.log(`System OS: ${sys.getPlatform()}`);
console.log(`System CPU Count: ${sys.getCPUCount()}`);
console.log(`System Free Memory: ${sys.getFreeMemory()}`);
console.log(`System Total Memory: ${sys.getTotalMemory()}`);
console.log(`System CPU Usage: ${sys.getCPUUsage()}%`);
// it's intentional to emit a warning
console.log(`System Memory by Megabytes:\n${inspect(sys.free(sys.Constants.FreeFlags.megabytes))}`);
console.log(`System Memory by Gigabytes:\n${inspect(sys.free('gigabytes'))}\n`);
console.log(`System Load Average by 1: ${sys.getLoadAvg(1)}`);
console.log(`System Load Average by 5: ${sys.getLoadAvg(5)}`);
console.log(`System CPU Model (${sys.getCPUInfo().firstModel}...${sys.getCPUInfo().lastModel}):\n${inspect(sys.getCPUInfo())}\n`);
console.log(`System Filesystem:\n${inspect(sys.getFilesystemInfo())}\n`);
console.log(`System Proccess by 10:\n${inspect(sys.getProcesses(10))}\n`);
console.log(`Unix Uptime:\n${inspect(sys.getUnixUptime())}`);
console.log(`Workstation: ${inspect(sys.getWindowsWorkstation())}`);
console.log(`Services: ${inspect(sys.getWindowsServices())}`);
console.log(`Motherboard: ${inspect(sys.getMotherboard())}`);
async function testerino() {
console.log(`@augu/sysinfo version: ${sys.version}`);
console.log(`System OS: ${sys.getPlatform()}`);
console.log(`System CPU Count: ${sys.getCPUCount()}`);
console.log(`System Free Memory: ${sys.getFreeMemory()}`);
console.log(`System Total Memory: ${sys.getTotalMemory()}`);
console.log(`System CPU Usage: ${sys.getCPUUsage()}%`);
// it's intentional to emit a warning
//console.log(`System Memory by Megabytes:\n${inspect(sys.free(sys.Constants.FreeFlags.megabytes))}`);
//console.log(`System Memory by Gigabytes:\n${inspect(sys.free('gigabytes'))}\n`);
console.log(`System Load Average by 1: ${sys.getLoadAvg(1)}`);
console.log(`System Load Average by 5: ${sys.getLoadAvg(5)}`);
console.log(`System CPU Model (${sys.getCPUInfo().firstModel}...${sys.getCPUInfo().lastModel}):\n${inspect(sys.getCPUInfo())}\n`);
//console.log(`System Filesystem:\n${inspect(sys.getFilesystemInfo())}\n`);
console.log(`System Proccess by 10:\n${inspect(await sys.getProcesses(10))}\n`);
//console.log(`Unix Uptime:\n${inspect(sys.getUnixUptime())}`);
console.log(`Workstation: ${inspect(sys.getWindowsWorkstation())}`);
console.log(`Services: ${inspect(sys.getWindowsServices())}`);
console.log(`Motherboard: ${inspect(sys.getMotherboard())}`);
}

testerino()
.then(process.exit)
.catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit 7923a22

Please sign in to comment.