mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 14:54:05 +00:00
Fix linting
This commit is contained in:
parent
1ca776df78
commit
4502b76832
6 changed files with 132 additions and 39 deletions
|
@ -1,21 +1,21 @@
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from "vite";
|
||||||
import vue from '@vitejs/plugin-vue';
|
import vue from "@vitejs/plugin-vue";
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from "url";
|
||||||
import { dirname, resolve } from 'path';
|
import { dirname, resolve } from "path";
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [ vue() ],
|
||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true,
|
||||||
environment: 'jsdom',
|
environment: "jsdom",
|
||||||
setupFiles: ['./test/component/setup.js'],
|
setupFiles: [ "./test/component/setup.js" ],
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, '../src'),
|
"@": resolve(__dirname, "../src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,30 @@ const { DnsMonitorType } = require("../../server/monitor-types/dns");
|
||||||
const { UP, DOWN } = require("../../src/util");
|
const { UP, DOWN } = require("../../src/util");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
|
|
||||||
|
test("DNSMonitor - Basic Creation Test", async (t) => {
|
||||||
|
const monitor = new DnsMonitorType();
|
||||||
|
assert.ok(monitor, "Should create monitor instance");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("DNSMonitor - Status Test", async (t) => {
|
||||||
|
const monitor = new DnsMonitorType();
|
||||||
|
|
||||||
|
// Test UP status
|
||||||
|
monitor.status = UP;
|
||||||
|
assert.strictEqual(monitor.status, UP, "Should set UP status");
|
||||||
|
|
||||||
|
// Test DOWN status
|
||||||
|
monitor.status = DOWN;
|
||||||
|
assert.strictEqual(monitor.status, DOWN, "Should set DOWN status");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("DNSMonitor - Timestamp Test", async (t) => {
|
||||||
|
const monitor = new DnsMonitorType();
|
||||||
|
const now = dayjs();
|
||||||
|
monitor.timestamp = now;
|
||||||
|
assert.strictEqual(monitor.timestamp.valueOf(), now.valueOf(), "Should set timestamp correctly");
|
||||||
|
});
|
||||||
|
|
||||||
test("DNS Monitor - Basic A Record Test", async (t) => {
|
test("DNS Monitor - Basic A Record Test", async (t) => {
|
||||||
const monitor = {
|
const monitor = {
|
||||||
hostname: "example.com",
|
hostname: "example.com",
|
||||||
|
@ -11,14 +35,14 @@ test("DNS Monitor - Basic A Record Test", async (t) => {
|
||||||
port: 53,
|
port: 53,
|
||||||
dns_resolve_type: "A"
|
dns_resolve_type: "A"
|
||||||
};
|
};
|
||||||
|
|
||||||
const heartbeat = {
|
const heartbeat = {
|
||||||
ping: 0
|
ping: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const dnsMonitor = new DnsMonitorType();
|
const dnsMonitor = new DnsMonitorType();
|
||||||
await dnsMonitor.check(monitor, heartbeat);
|
await dnsMonitor.check(monitor, heartbeat);
|
||||||
|
|
||||||
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
||||||
assert.ok(Array.isArray(heartbeat.dnsRecords), "DNS records should be an array");
|
assert.ok(Array.isArray(heartbeat.dnsRecords), "DNS records should be an array");
|
||||||
});
|
});
|
||||||
|
@ -30,7 +54,7 @@ test("DNS Monitor - Invalid Domain Test", async (t) => {
|
||||||
port: 53,
|
port: 53,
|
||||||
dns_resolve_type: "A"
|
dns_resolve_type: "A"
|
||||||
};
|
};
|
||||||
|
|
||||||
const heartbeat = {
|
const heartbeat = {
|
||||||
ping: 0
|
ping: 0
|
||||||
};
|
};
|
||||||
|
@ -51,14 +75,14 @@ test("DNS Monitor - Custom DNS Server Test", async (t) => {
|
||||||
port: 53,
|
port: 53,
|
||||||
dns_resolve_type: "A"
|
dns_resolve_type: "A"
|
||||||
};
|
};
|
||||||
|
|
||||||
const heartbeat = {
|
const heartbeat = {
|
||||||
ping: 0
|
ping: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const dnsMonitor = new DnsMonitorType();
|
const dnsMonitor = new DnsMonitorType();
|
||||||
await dnsMonitor.check(monitor, heartbeat);
|
await dnsMonitor.check(monitor, heartbeat);
|
||||||
|
|
||||||
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -69,14 +93,14 @@ test("DNS Monitor - TXT Record Test", async (t) => {
|
||||||
port: 53,
|
port: 53,
|
||||||
dns_resolve_type: "TXT"
|
dns_resolve_type: "TXT"
|
||||||
};
|
};
|
||||||
|
|
||||||
const heartbeat = {
|
const heartbeat = {
|
||||||
ping: 0
|
ping: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const dnsMonitor = new DnsMonitorType();
|
const dnsMonitor = new DnsMonitorType();
|
||||||
await dnsMonitor.check(monitor, heartbeat);
|
await dnsMonitor.check(monitor, heartbeat);
|
||||||
|
|
||||||
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
||||||
assert.ok(Array.isArray(heartbeat.dnsRecords), "DNS records should be an array");
|
assert.ok(Array.isArray(heartbeat.dnsRecords), "DNS records should be an array");
|
||||||
});
|
});
|
||||||
|
@ -93,13 +117,13 @@ test("DNS Monitor - Condition Evaluation Test", async (t) => {
|
||||||
value: "93.184.216.34" // example.com's IP (this might change)
|
value: "93.184.216.34" // example.com's IP (this might change)
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
const heartbeat = {
|
const heartbeat = {
|
||||||
ping: 0
|
ping: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const dnsMonitor = new DnsMonitorType();
|
const dnsMonitor = new DnsMonitorType();
|
||||||
await dnsMonitor.check(monitor, heartbeat);
|
await dnsMonitor.check(monitor, heartbeat);
|
||||||
|
|
||||||
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
assert.ok(heartbeat.ping > 0, "Ping should be recorded");
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,12 +11,12 @@ test("Notification - Basic Creation Test", async (t) => {
|
||||||
|
|
||||||
test("Notification - Format Message Test", async (t) => {
|
test("Notification - Format Message Test", async (t) => {
|
||||||
const notification = new Notification();
|
const notification = new Notification();
|
||||||
|
|
||||||
const monitor = {
|
const monitor = {
|
||||||
name: "Test Monitor",
|
name: "Test Monitor",
|
||||||
hostname: "example.com"
|
hostname: "example.com"
|
||||||
};
|
};
|
||||||
|
|
||||||
const msg = {
|
const msg = {
|
||||||
type: "down",
|
type: "down",
|
||||||
monitor,
|
monitor,
|
||||||
|
@ -29,28 +29,52 @@ test("Notification - Format Message Test", async (t) => {
|
||||||
assert.ok(formatted.includes("Connection failed"), "Should include error message");
|
assert.ok(formatted.includes("Connection failed"), "Should include error message");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Notification - Status Test", async (t) => {
|
||||||
|
const notification = new Notification();
|
||||||
|
|
||||||
|
// Test UP status
|
||||||
|
const upMsg = {
|
||||||
|
type: "up",
|
||||||
|
monitor: { name: "Test1" },
|
||||||
|
msg: "Service is up",
|
||||||
|
status: UP
|
||||||
|
};
|
||||||
|
const upFormatted = notification.format(upMsg);
|
||||||
|
assert.ok(upFormatted.includes("up"), "Should indicate UP status");
|
||||||
|
|
||||||
|
// Test DOWN status
|
||||||
|
const downMsg = {
|
||||||
|
type: "down",
|
||||||
|
monitor: { name: "Test2" },
|
||||||
|
msg: "Service is down",
|
||||||
|
status: DOWN
|
||||||
|
};
|
||||||
|
const downFormatted = notification.format(downMsg);
|
||||||
|
assert.ok(downFormatted.includes("down"), "Should indicate DOWN status");
|
||||||
|
});
|
||||||
|
|
||||||
test("Notification - Queue Management Test", async (t) => {
|
test("Notification - Queue Management Test", async (t) => {
|
||||||
const notification = new Notification();
|
const notification = new Notification();
|
||||||
|
|
||||||
// Add items to queue
|
// Add items to queue
|
||||||
notification.add({
|
notification.add({
|
||||||
type: "down",
|
type: "down",
|
||||||
monitor: { name: "Test1" },
|
monitor: { name: "Test1" },
|
||||||
msg: "Error 1"
|
msg: "Error 1"
|
||||||
});
|
});
|
||||||
|
|
||||||
notification.add({
|
notification.add({
|
||||||
type: "up",
|
type: "up",
|
||||||
monitor: { name: "Test2" },
|
monitor: { name: "Test2" },
|
||||||
msg: "Recovered"
|
msg: "Recovered"
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(notification.queue.length, 2, "Queue should have 2 items");
|
assert.strictEqual(notification.queue.length, 2, "Queue should have 2 items");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Notification - Priority Test", async (t) => {
|
test("Notification - Priority Test", async (t) => {
|
||||||
const notification = new Notification();
|
const notification = new Notification();
|
||||||
|
|
||||||
// Add items with different priorities
|
// Add items with different priorities
|
||||||
notification.add({
|
notification.add({
|
||||||
type: "down",
|
type: "down",
|
||||||
|
@ -58,21 +82,21 @@ test("Notification - Priority Test", async (t) => {
|
||||||
msg: "Critical Error",
|
msg: "Critical Error",
|
||||||
priority: "high"
|
priority: "high"
|
||||||
});
|
});
|
||||||
|
|
||||||
notification.add({
|
notification.add({
|
||||||
type: "down",
|
type: "down",
|
||||||
monitor: { name: "Test2" },
|
monitor: { name: "Test2" },
|
||||||
msg: "Warning",
|
msg: "Warning",
|
||||||
priority: "low"
|
priority: "low"
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextItem = notification.queue[0];
|
const nextItem = notification.queue[0];
|
||||||
assert.strictEqual(nextItem.priority, "high", "High priority item should be first");
|
assert.strictEqual(nextItem.priority, "high", "High priority item should be first");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Notification - Retry Logic Test", async (t) => {
|
test("Notification - Retry Logic Test", async (t) => {
|
||||||
const notification = new Notification();
|
const notification = new Notification();
|
||||||
|
|
||||||
const testMsg = {
|
const testMsg = {
|
||||||
type: "down",
|
type: "down",
|
||||||
monitor: { name: "Test1" },
|
monitor: { name: "Test1" },
|
||||||
|
@ -80,9 +104,9 @@ test("Notification - Retry Logic Test", async (t) => {
|
||||||
retries: 0,
|
retries: 0,
|
||||||
maxRetries: 3
|
maxRetries: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
notification.add(testMsg);
|
notification.add(testMsg);
|
||||||
|
|
||||||
// Simulate failed send
|
// Simulate failed send
|
||||||
try {
|
try {
|
||||||
await notification.send(testMsg);
|
await notification.send(testMsg);
|
||||||
|
@ -95,7 +119,7 @@ test("Notification - Retry Logic Test", async (t) => {
|
||||||
test("Notification - Rate Limiting Test", async (t) => {
|
test("Notification - Rate Limiting Test", async (t) => {
|
||||||
const notification = new Notification();
|
const notification = new Notification();
|
||||||
const monitor = { name: "Test Monitor" };
|
const monitor = { name: "Test Monitor" };
|
||||||
|
|
||||||
// Add multiple notifications for same monitor
|
// Add multiple notifications for same monitor
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
notification.add({
|
notification.add({
|
||||||
|
@ -104,11 +128,11 @@ test("Notification - Rate Limiting Test", async (t) => {
|
||||||
msg: `Error ${i}`
|
msg: `Error ${i}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if rate limiting is applied
|
// Check if rate limiting is applied
|
||||||
const processedCount = notification.queue.filter(
|
const processedCount = notification.queue.filter(
|
||||||
item => item.monitor.name === "Test Monitor"
|
item => item.monitor.name === "Test Monitor"
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
assert.ok(processedCount < 5, "Should apply rate limiting");
|
assert.ok(processedCount < 5, "Should apply rate limiting");
|
||||||
});
|
});
|
||||||
|
|
|
@ -73,7 +73,7 @@ describe("MonitorList.vue", () => {
|
||||||
MonitorListItem: {
|
MonitorListItem: {
|
||||||
name: "MonitorListItem",
|
name: "MonitorListItem",
|
||||||
template: "<div class='monitor-list-item' :class='{ active: active }' @click='$emit(\"click\")'><slot></slot></div>",
|
template: "<div class='monitor-list-item' :class='{ active: active }' @click='$emit(\"click\")'><slot></slot></div>",
|
||||||
props: ["active"]
|
props: [ "active" ]
|
||||||
},
|
},
|
||||||
Confirm: true,
|
Confirm: true,
|
||||||
MonitorListFilter: true,
|
MonitorListFilter: true,
|
||||||
|
@ -93,7 +93,7 @@ describe("MonitorList.vue", () => {
|
||||||
const items = wrapper.findAll("[data-testid='monitor-list'] .monitor-list-item");
|
const items = wrapper.findAll("[data-testid='monitor-list'] .monitor-list-item");
|
||||||
await items[0].trigger("click");
|
await items[0].trigger("click");
|
||||||
expect(wrapper.emitted("select-monitor")).toBeTruthy();
|
expect(wrapper.emitted("select-monitor")).toBeTruthy();
|
||||||
expect(wrapper.emitted("select-monitor")[0]).toEqual([1]);
|
expect(wrapper.emitted("select-monitor")[0]).toEqual([ 1 ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("applies active class to selected monitor", async () => {
|
it("applies active class to selected monitor", async () => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||||
import { mount } from "@vue/test-utils";
|
import { mount } from "@vue/test-utils";
|
||||||
import PingChart from "../../src/components/PingChart.vue";
|
import PingChart from "../../src/components/PingChart.vue";
|
||||||
|
import { Line } from "vue-chartjs";
|
||||||
|
|
||||||
// Mock Chart.js
|
// Mock Chart.js
|
||||||
vi.mock("chart.js", () => ({
|
vi.mock("chart.js", () => ({
|
||||||
|
@ -8,6 +9,14 @@ vi.mock("chart.js", () => ({
|
||||||
registerables: []
|
registerables: []
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Mock vue-chartjs
|
||||||
|
vi.mock("vue-chartjs", () => ({
|
||||||
|
Line: {
|
||||||
|
name: "Line",
|
||||||
|
template: "<canvas></canvas>"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
describe("PingChart.vue", () => {
|
describe("PingChart.vue", () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
const mockMonitorId = 1;
|
const mockMonitorId = 1;
|
||||||
|
|
|
@ -18,25 +18,25 @@ describe("Status.vue", () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
it("renders UP status correctly", () => {
|
it("renders UP status correctly", () => {
|
||||||
const wrapper = mountStatus(1); // UP status
|
const wrapper = mountStatus(UP); // UP status
|
||||||
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
||||||
expect(wrapper.text()).toBe("Up");
|
expect(wrapper.text()).toBe("Up");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders DOWN status correctly", () => {
|
it("renders DOWN status correctly", () => {
|
||||||
const wrapper = mountStatus(0); // DOWN status
|
const wrapper = mountStatus(DOWN); // DOWN status
|
||||||
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
||||||
expect(wrapper.text()).toBe("Down");
|
expect(wrapper.text()).toBe("Down");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders PENDING status correctly", () => {
|
it("renders PENDING status correctly", () => {
|
||||||
const wrapper = mountStatus(2); // PENDING status
|
const wrapper = mountStatus(PENDING); // PENDING status
|
||||||
expect(wrapper.find(".badge").classes()).toContain("bg-warning");
|
expect(wrapper.find(".badge").classes()).toContain("bg-warning");
|
||||||
expect(wrapper.text()).toBe("Pending");
|
expect(wrapper.text()).toBe("Pending");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders MAINTENANCE status correctly", () => {
|
it("renders MAINTENANCE status correctly", () => {
|
||||||
const wrapper = mountStatus(3); // MAINTENANCE status
|
const wrapper = mountStatus(MAINTENANCE); // MAINTENANCE status
|
||||||
expect(wrapper.find(".badge").classes()).toContain("bg-maintenance");
|
expect(wrapper.find(".badge").classes()).toContain("bg-maintenance");
|
||||||
expect(wrapper.text()).toBe("statusMaintenance");
|
expect(wrapper.text()).toBe("statusMaintenance");
|
||||||
});
|
});
|
||||||
|
@ -48,10 +48,46 @@ describe("Status.vue", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("updates when status prop changes", async () => {
|
it("updates when status prop changes", async () => {
|
||||||
const wrapper = mountStatus(1); // UP status
|
const wrapper = mountStatus(UP); // UP status
|
||||||
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
||||||
|
|
||||||
await wrapper.setProps({ status: 0 }); // Change to DOWN status
|
await wrapper.setProps({ status: DOWN }); // Change to DOWN status
|
||||||
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("displays correct status classes", async () => {
|
||||||
|
// Test UP status
|
||||||
|
const wrapper = mountStatus(UP);
|
||||||
|
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
||||||
|
|
||||||
|
// Test DOWN status
|
||||||
|
await wrapper.setProps({ status: DOWN });
|
||||||
|
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
||||||
|
|
||||||
|
// Test PENDING status
|
||||||
|
await wrapper.setProps({ status: PENDING });
|
||||||
|
expect(wrapper.find(".badge").classes()).toContain("bg-warning");
|
||||||
|
|
||||||
|
// Test MAINTENANCE status
|
||||||
|
await wrapper.setProps({ status: MAINTENANCE });
|
||||||
|
expect(wrapper.find(".badge").classes()).toContain("bg-maintenance");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("displays correct status text", async () => {
|
||||||
|
// Test UP status
|
||||||
|
const wrapper = mountStatus(UP);
|
||||||
|
expect(wrapper.text()).toBe("Up");
|
||||||
|
|
||||||
|
// Test DOWN status
|
||||||
|
await wrapper.setProps({ status: DOWN });
|
||||||
|
expect(wrapper.text()).toBe("Down");
|
||||||
|
|
||||||
|
// Test PENDING status
|
||||||
|
await wrapper.setProps({ status: PENDING });
|
||||||
|
expect(wrapper.text()).toBe("Pending");
|
||||||
|
|
||||||
|
// Test MAINTENANCE status
|
||||||
|
await wrapper.setProps({ status: MAINTENANCE });
|
||||||
|
expect(wrapper.text()).toBe("statusMaintenance");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue