smartnetwork/test/test.ping.ts

31 lines
1.0 KiB
TypeScript

import { tap, expect, expectAsync } from '@push.rocks/tapbundle';
import * as smartnetwork from '../ts/index.js';
let testSmartnetwork: smartnetwork.SmartNetwork;
tap.test('should create a vlid instance of SmartNetwork', async () => {
testSmartnetwork = new smartnetwork.SmartNetwork();
expect(testSmartnetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
});
tap.test('should send a ping to Google', async () => {
const res = await testSmartnetwork.ping('google.com');
console.log(res);
// verify basic ping response properties
expect(res.alive).toBeTrue();
expect(res.time).toBeTypeofNumber();
expect(res.output).toBeTypeofString();
expect(res.output).toMatch(/PING google\.com/);
});
tap.test('should state when a ping is not alive ', async () => {
await expectAsync(testSmartnetwork.ping('notthere.lossless.com')).property('alive').toBeFalse();
});
tap.test('should send a ping to an IP', async () => {
await expectAsync(testSmartnetwork.ping('192.168.186.999')).property('alive').toBeFalse();
});
tap.start();