diff --git a/lib/index.ts b/lib/index.ts index d426a69..5b65557 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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); } /** diff --git a/lib/test.ts b/lib/test.ts index 2436f95..2f31b7c 100644 --- a/lib/test.ts +++ b/lib/test.ts @@ -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) => { diff --git a/src/addon.cc b/src/addon.cc index 6fd43fd..cfb4d5d 100644 --- a/src/addon.cc +++ b/src/addon.cc @@ -37,12 +37,12 @@ void GetProcessCpuUsage(const Nan::FunctionCallbackInfo& 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; }