Skip to content

Commit

Permalink
Merge pull request #47 from rwe/fix-cpu-type-messages
Browse files Browse the repository at this point in the history
fix: incorrect `getProcessCpuUsage` type error messages
  • Loading branch information
Tyriar authored Nov 9, 2022
2 parents 2318db2 + ab5500b commit 5049659
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function getProcessList(rootPid: number, callback: (processList: IProcess
* @param callback The callback to use with the returned list of processes
*/
export function getProcessCpuUsage(processList: IProcessInfo[], callback: (tree: IProcessCpuInfo[]) => void): void {
native.getProcessCpuUsage(processList, (processListWithCpu) => callback(processListWithCpu));
native.getProcessCpuUsage(processList, callback);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions lib/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ describe('getProcessList', () => {
});

describe('getProcessCpuUsage', () => {
it('should throw on incorrect argument types', done => {
assert.throws(() => getProcessCpuUsage('<…>' as any, () => null), /processList.*array/);
assert.throws(() => getProcessCpuUsage([], '<…>' as any), /callback.*function/);
done();
});

it('should get process cpu usage', (done) => {
getProcessCpuUsage([{ pid: process.pid, ppid: process.ppid, name: 'node.exe' }], (annotatedList) => {
Expand Down
4 changes: 2 additions & 2 deletions src/addon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ void GetProcessCpuUsage(const Nan::FunctionCallbackInfo<v8::Value>& args) {
}

if (!args[0]->IsArray()) {
Nan::ThrowTypeError("The first argument of GetProcessCpuUsage, callback, must be an array.");
Nan::ThrowTypeError("The first argument of GetProcessCpuUsage, processList, must be an array.");
return;
}

if (!args[1]->IsFunction()) {
Nan::ThrowTypeError("The second argument of GetProcessCpuUsage, flags, must be a function.");
Nan::ThrowTypeError("The second argument of GetProcessCpuUsage, callback, must be a function.");
return;
}

Expand Down

0 comments on commit 5049659

Please sign in to comment.