Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/ping-sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var ping = require('./ping-promise');
/**
* Callback after probing given host
* @callback probeCallback
* @param {boolean} isAlive - Whether target is alive or not
* @param {import('./parser/base').PingResponse} response - Ping response object
* @param {Error|null} error - Error object if error occurs, null otherwise
*/

Expand All @@ -34,14 +34,14 @@ var ping = require('./ping-promise');
* @param {string} addr - Hostname or ip address
* @param {probeCallback} cb - Callback
* @param {import('./index').PingConfig} [config] - Configuration for command ping
* @return {Promise} Promise from the underlying ping operation
* @return {Promise<import('./parser/base').PingResponse>} Promise from the underlying ping operation
*/
function probe(addr, cb, config) {
// Do not reassign function parameter
var _config = config || {};

return ping.probe(addr, _config).then(function (res) {
cb(res.alive, null);
cb(res, null);
}).catch(function (err) {
cb(null, err);
});
Expand Down
10 changes: 7 additions & 3 deletions test/test-ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,13 @@ describe('Ping in callback mode', function () {
stub.restore();
}).then(function (data) {
var answerKey = pathToAnswerKey(fp);
var actualIsAlive = data;
var expectIsAlive = ANSWER[answerKey].alive;
expect(actualIsAlive).to.equal(expectIsAlive);
var actualData = data;
var expectData = ANSWER[answerKey];
var trimTraillingNewlineActualOutput = actualData.output.trim();
var trimTraillingNewlineExpectOutput = expectData.output.trim();
actualData.output = trimTraillingNewlineActualOutput;
expectData.output = trimTraillingNewlineExpectOutput;
expect(actualData).to.deep.equal(expectData);
});
};

Expand Down
4 changes: 2 additions & 2 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const pingConfig: PingConfig = {
};

expectType<Promise<PingResponse>>(promiseProbe('localhost', pingConfig));
expectType<Promise<any>>(callbackProbe('localhost', (isAlive, error) => {
expectType<boolean>(isAlive);
expectType<Promise<PingResponse>>(callbackProbe('localhost', (response, error) => {
expectType<PingResponse>(response);
expectType<Error | null>(error);
}, pingConfig));

Expand Down
8 changes: 4 additions & 4 deletions types/ping-sys.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/**
* Callback after probing given host
*/
export type probeCallback = (isAlive: boolean, error: Error | null) => any;
export type probeCallback = (response: import("./parser/base").PingResponse, error: Error | null) => any;
/**
* @module ping/ping-sys
*/
/**
* Callback after probing given host
* @callback probeCallback
* @param {boolean} isAlive - Whether target is alive or not
* @param {import('./parser/base').PingResponse} response - Ping response object
* @param {Error|null} error - Error object if error occurs, null otherwise
*/
/**
* Probe a host using ping command with callback interface
* @param {string} addr - Hostname or ip address
* @param {probeCallback} cb - Callback
* @param {import('./index').PingConfig} [config] - Configuration for command ping
* @return {Promise} Promise from the underlying ping operation
* @return {Promise<import('./parser/base').PingResponse>} Promise from the underlying ping operation
*/
export function probe(addr: string, cb: probeCallback, config?: import("./index").PingConfig): Promise<any>;
export function probe(addr: string, cb: probeCallback, config?: import("./index").PingConfig): Promise<import("./parser/base").PingResponse>;
//# sourceMappingURL=ping-sys.d.ts.map