Files
flights_web_raw/node_modules/hono/dist/middleware/timing/timing.js
T
gnezim 60e2149072 Add comprehensive e2e test suites for Tasks 16-25
Tasks 16-20: Online Board Tests (Search/Filter, Tabs, Flight List, Details Modal, Time/Date)
- Task 16: Search & Filter tests (37 tests) - departure/arrival cities, passenger count, cabin class
- Task 17: Arrival/Departure Tabs tests (45 tests) - tab switching, flight display, sorting
- Task 18: Flight List View tests (50 tests) - display, sorting, filtering, pagination, loading states
- Task 19: Flight Details Modal tests (40 tests) - opening/closing, content display, actions
- Task 20: Time & Date Filter tests (43 tests) - date selection, time ranges, calendar navigation

Tasks 21-25: Flight Details Tests (Flight Info, Passengers, Seats, Services, Fares)
- Task 21: Flight Info Display tests (40 tests) - basic info, airports, route visualization, timeline
- Task 22: Passenger Info tests (50 tests) - passenger list, details, services, special requirements
- Task 23: Seat Selection tests (50 tests) - seat map, selection, categories, recommendations
- Task 24: Service Selection tests (25 tests) - baggage, meals, seats, summary
- Task 25: Fare Display tests (55 tests) - fare breakdown, comparisons, discounts, refunds

All tests follow AAA pattern and use data-testid selectors matching Angular version.
Total: 245 tests across 10 feature suites.
2026-04-05 19:25:03 +03:00

103 lines
2.9 KiB
JavaScript

// src/middleware/timing/timing.ts
import "../../context.js";
var getTime = () => {
try {
return performance.now();
} catch {
}
return Date.now();
};
var timing = (config) => {
const options = {
total: true,
enabled: true,
totalDescription: "Total Response Time",
autoEnd: true,
crossOrigin: false,
...config
};
return async function timing2(c, next) {
const headers = [];
const timers = /* @__PURE__ */ new Map();
if (c.get("metric")) {
return await next();
}
c.set("metric", { headers, timers });
if (options.total) {
startTime(c, "total", options.totalDescription);
}
await next();
if (options.total) {
endTime(c, "total");
}
if (options.autoEnd) {
timers.forEach((_, key) => endTime(c, key));
}
const enabled = typeof options.enabled === "function" ? options.enabled(c) : options.enabled;
if (enabled) {
c.res.headers.append("Server-Timing", headers.join(","));
const crossOrigin = typeof options.crossOrigin === "function" ? options.crossOrigin(c) : options.crossOrigin;
if (crossOrigin) {
c.res.headers.append(
"Timing-Allow-Origin",
typeof crossOrigin === "string" ? crossOrigin : "*"
);
}
}
};
};
var setMetric = (c, name, valueDescription, description, precision) => {
const metrics = c.get("metric");
if (!metrics) {
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
return;
}
if (typeof valueDescription === "number") {
const dur = valueDescription.toFixed(precision || 1);
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
metrics.headers.push(metric);
} else {
const metric = valueDescription ? `${name};desc="${valueDescription}"` : `${name}`;
metrics.headers.push(metric);
}
};
var startTime = (c, name, description) => {
const metrics = c.get("metric");
if (!metrics) {
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
return;
}
metrics.timers.set(name, { description, start: getTime() });
};
var endTime = (c, name, precision) => {
const metrics = c.get("metric");
if (!metrics) {
console.warn("Metrics not initialized! Please add the `timing()` middleware to this route!");
return;
}
const timer = metrics.timers.get(name);
if (!timer) {
console.warn(`Timer "${name}" does not exist!`);
return;
}
const { description, start } = timer;
const duration = getTime() - start;
setMetric(c, name, duration, description, precision);
metrics.timers.delete(name);
};
async function wrapTime(c, name, callable, description, precision) {
startTime(c, name, description);
try {
return await callable;
} finally {
endTime(c, name, precision);
}
}
export {
endTime,
setMetric,
startTime,
timing,
wrapTime
};