46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
|
import * as detector from '../ts/index.js';
|
|
|
|
let testDetector: detector.Detector;
|
|
|
|
tap.test('first test', async () => {
|
|
testDetector = new detector.Detector();
|
|
expect(testDetector).toBeInstanceOf(detector.Detector);
|
|
});
|
|
|
|
tap.test('should detect an closed port on a local domain', async () => {
|
|
const result = await testDetector.isActive('http://localhost:3008');
|
|
expect(result.isActive).toBeFalse();
|
|
});
|
|
|
|
tap.test('should detect an open port on a remote domain', async () => {
|
|
const result = await testDetector.isActive('https://lossless.com');
|
|
expect(result.isActive).toBeTrue();
|
|
});
|
|
|
|
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();
|