Files
detector/test/test.ts

46 lines
1.6 KiB
TypeScript
Raw Normal View History

import { expect, tap } from '@git.zone/tstest/tapbundle';
2022-07-16 18:15:23 +02:00
import * as detector from '../ts/index.js';
2021-04-12 19:00:08 +00:00
2021-04-13 08:30:33 +00:00
let testDetector: detector.Detector;
2021-04-12 19:00:08 +00:00
tap.test('first test', async () => {
2021-04-13 08:30:33 +00:00
testDetector = new detector.Detector();
2022-07-16 18:15:23 +02:00
expect(testDetector).toBeInstanceOf(detector.Detector);
2021-04-13 08:30:33 +00:00
});
2021-04-14 11:47:51 +00:00
tap.test('should detect an closed port on a local domain', async () => {
const result = await testDetector.isActive('http://localhost:3008');
expect(result.isActive).toBeFalse();
2021-04-14 11:47:51 +00:00
});
tap.test('should detect an open port on a remote domain', async () => {
2021-04-13 08:30:33 +00:00
const result = await testDetector.isActive('https://lossless.com');
expect(result.isActive).toBeTrue();
2021-04-12 19:00:08 +00:00
});
tap.test('should detect service type for HTTP', async () => {
const result = await testDetector.isActive('http://example.com', { detectServiceType: true });
expect(result.isActive).toBeTrue();
expect(result.serviceType).toEqual(detector.ServiceType.HTTP);
});
tap.test('should detect service type for HTTPS', async () => {
const result = await testDetector.isActive('https://example.com', { detectServiceType: true });
expect(result.isActive).toBeTrue();
expect(result.serviceType).toEqual(detector.ServiceType.HTTPS);
});
tap.test('should detect SSH service', async () => {
const sshType = await testDetector.detectType('ssh://github.com:22');
expect(sshType).toEqual(detector.ServiceType.SSH);
});
tap.test('should return unknown for non-standard services', async () => {
const result = await testDetector.isActive('http://localhost:9999', { detectServiceType: true });
if (result.isActive) {
expect(result.serviceType).toEqual(detector.ServiceType.UNKNOWN);
}
});
export default tap.start();