mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Update Probe npm install and test commands
This commit is contained in:
3
.github/workflows/test.probe.yaml
vendored
3
.github/workflows/test.probe.yaml
vendored
@@ -19,5 +19,6 @@ jobs:
|
||||
node-version: 18.3.0
|
||||
- run: cd Common && npm install
|
||||
- run: cd CommonServer && npm install
|
||||
- run: cd Probe && npm install && npm run test
|
||||
- run: cd Probe && npm install
|
||||
- run: cd Probe && npm run test
|
||||
|
||||
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
@@ -334,6 +334,19 @@
|
||||
"debug:test"
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Probe: Debug Tests",
|
||||
"type": "node",
|
||||
"restart": true,
|
||||
"autoAttachChildProcesses": true,
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceRoot}/Probe",
|
||||
"runtimeExecutable": "npm",
|
||||
"runtimeArgs": [
|
||||
"run-script",
|
||||
"debug:test"
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Accounts: Debug Local Files",
|
||||
"type": "node",
|
||||
|
||||
@@ -57,9 +57,9 @@ export default class WebsiteRequest {
|
||||
return {
|
||||
url: url,
|
||||
requestHeaders: options.headers || {},
|
||||
responseHeaders: response.headers as Dictionary<string>,
|
||||
responseStatusCode: response.status,
|
||||
responseBody: new HTML(response.data),
|
||||
responseHeaders: response!.headers as Dictionary<string>,
|
||||
responseStatusCode: response!.status,
|
||||
responseBody: new HTML(response!.data),
|
||||
isOnline: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,19 +4,20 @@ import PositiveNumber from 'Common/Types/PositiveNumber';
|
||||
import Ping, {
|
||||
PingResponse,
|
||||
} from '../../Utils/Monitors/MonitorTypes/PingMonitor';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
|
||||
describe('Ping', () => {
|
||||
jest.setTimeout(10000);
|
||||
jest.setTimeout(120000);
|
||||
test('Ping.ping should return appropriate object if the valid hostname is given', async () => {
|
||||
let result: PingResponse | null = await Ping.ping(
|
||||
new Hostname('google.com', 80)
|
||||
new Hostname('google.com')
|
||||
);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
expect(result!.isOnline).toBe(true);
|
||||
result = await Ping.ping(new Hostname('www.google.com', 80), {
|
||||
result = await Ping.ping(new Hostname('www.google.com'), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
|
||||
@@ -25,22 +26,24 @@ describe('Ping', () => {
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeGreaterThan(0);
|
||||
expect(result!.responseTimeInMS?.toNumber()).toBeLessThanOrEqual(5000);
|
||||
|
||||
result = await Ping.ping(new Hostname('www.google.com', 65000), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isOnline).toBe(false);
|
||||
expect(result!.responseTimeInMS).toBeUndefined();
|
||||
try {
|
||||
await Ping.ping(new Hostname('www.google.com', 65000), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
} catch (err) {
|
||||
expect(err).toBeInstanceOf(BadDataException);
|
||||
}
|
||||
|
||||
result = await Ping.ping(new Hostname('www.a.com', 65000), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.isOnline).toBe(false);
|
||||
expect(result!.isOnline).toBe(false);
|
||||
expect(result!.responseTimeInMS).toBeUndefined();
|
||||
try {
|
||||
await Ping.ping(new Hostname('www.a.com', 65000), {
|
||||
timeout: new PositiveNumber(5000),
|
||||
});
|
||||
} catch (err) {
|
||||
expect(err).toBeInstanceOf(BadDataException);
|
||||
}
|
||||
});
|
||||
test('Ping.ping should return appropriate object if the valid IPV4 or IPV6 is given', async () => {
|
||||
// change test timeout to 2 minutes
|
||||
let result: PingResponse | null = null;
|
||||
|
||||
result = await Ping.ping(new IPv4('172.217.170.206'), {
|
||||
|
||||
@@ -8,6 +8,7 @@ import logger from 'CommonServer/Utils/Logger';
|
||||
import ping from 'ping';
|
||||
import UnableToReachServer from 'Common/Types/Exception/UnableToReachServer';
|
||||
import Sleep from 'Common/Types/Sleep';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
|
||||
// TODO - make sure it work for the IPV6
|
||||
export interface PingResponse {
|
||||
@@ -79,6 +80,12 @@ export default class PingMonitor {
|
||||
let hostAddress: string = '';
|
||||
if (host instanceof Hostname) {
|
||||
hostAddress = host.hostname;
|
||||
|
||||
if (host.port) {
|
||||
throw new BadDataException(
|
||||
'Port is not supported for ping monitor'
|
||||
);
|
||||
}
|
||||
} else if (host instanceof URL) {
|
||||
hostAddress = host.hostname.hostname;
|
||||
} else {
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"dev": "npx nodemon",
|
||||
"audit": "npm audit --audit-level=low",
|
||||
"dep-check": "depcheck ./ --skip-missing=true",
|
||||
"test": "jest --passWithNoTests"
|
||||
"test": "jest --passWithNoTests",
|
||||
"debug:test": "node --inspect node_modules/.bin/jest --runInBand ./Tests --detectOpenHandles"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM node:18.18.1-alpine
|
||||
FROM node:current-alpine
|
||||
USER root
|
||||
RUN mkdir /tmp/npm && chmod 2777 /tmp/npm && chown 1000:1000 /tmp/npm && npm config set cache /tmp/npm --global
|
||||
|
||||
@@ -12,7 +12,6 @@ ARG APP_VERSION
|
||||
ENV GIT_SHA=${GIT_SHA}
|
||||
ENV APP_VERSION=${APP_VERSION}
|
||||
|
||||
RUN npm -g config set user root
|
||||
RUN apk add bash
|
||||
|
||||
COPY ./Tests .
|
||||
|
||||
Reference in New Issue
Block a user