test: fix debug test case
This commit is contained in:
@@ -21,4 +21,6 @@ module.exports = async (ctx, next) => {
|
||||
if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
|
||||
ctx.debug.hitCache++;
|
||||
}
|
||||
|
||||
ctx.state.debuged = true;
|
||||
};
|
||||
|
||||
@@ -42,6 +42,17 @@ module.exports = async (ctx, next) => {
|
||||
}
|
||||
ctx.debug.errorRoutes[ctx._matchedRoute]++;
|
||||
|
||||
if (!ctx.state.debuged) {
|
||||
if (!ctx.debug.routes[ctx._matchedRoute]) {
|
||||
ctx.debug.routes[ctx._matchedRoute] = 0;
|
||||
}
|
||||
ctx.debug.routes[ctx._matchedRoute]++;
|
||||
|
||||
if (ctx.response.get('X-Koa-Redis-Cache') || ctx.response.get('X-Koa-Memory-Cache')) {
|
||||
ctx.debug.hitCache++;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.sentry) {
|
||||
Sentry.withScope((scope) => {
|
||||
scope.setTag('route', ctx._matchedRoute);
|
||||
|
||||
+5
-5
@@ -19,14 +19,14 @@ module.exports = async (ctx) => {
|
||||
const hotRoutes = routes.slice(0, 30);
|
||||
let hotRoutesValue = '';
|
||||
hotRoutes.forEach((item) => {
|
||||
hotRoutesValue += `${ctx.debug.routes[item]} ${item}<br>`;
|
||||
hotRoutesValue += `${ctx.debug.routes[item]} ${item}<br>`;
|
||||
});
|
||||
|
||||
const paths = Object.keys(ctx.debug.paths).sort((a, b) => ctx.debug.paths[b] - ctx.debug.paths[a]);
|
||||
const hotPaths = paths.slice(0, 30);
|
||||
let hotPathsValue = '';
|
||||
hotPaths.forEach((item) => {
|
||||
hotPathsValue += `${ctx.debug.paths[item]} ${item}<br>`;
|
||||
hotPathsValue += `${ctx.debug.paths[item]} ${item}<br>`;
|
||||
});
|
||||
|
||||
let hotErrorRoutesValue = '';
|
||||
@@ -34,7 +34,7 @@ module.exports = async (ctx) => {
|
||||
const errorRoutes = Object.keys(ctx.debug.errorRoutes).sort((a, b) => ctx.debug.errorRoutes[b] - ctx.debug.errorRoutes[a]);
|
||||
const hotErrorRoutes = errorRoutes.slice(0, 30);
|
||||
hotErrorRoutes.forEach((item) => {
|
||||
hotErrorRoutesValue += `${ctx.debug.errorRoutes[item]} ${item}<br>`;
|
||||
hotErrorRoutesValue += `${ctx.debug.errorRoutes[item]} ${item}<br>`;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ module.exports = async (ctx) => {
|
||||
const errorPaths = Object.keys(ctx.debug.errorPaths).sort((a, b) => ctx.debug.errorPaths[b] - ctx.debug.errorPaths[a]);
|
||||
const hotErrorPaths = errorPaths.slice(0, 30);
|
||||
hotErrorPaths.forEach((item) => {
|
||||
hotErrorPathsValue += `${ctx.debug.errorPaths[item]} ${item}<br>`;
|
||||
hotErrorPathsValue += `${ctx.debug.errorPaths[item]} ${item}<br>`;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ module.exports = async (ctx) => {
|
||||
const hotIPs = ips.slice(0, 50);
|
||||
let hotIPsValue = '';
|
||||
hotIPs.forEach((item) => {
|
||||
hotIPsValue += `${ctx.debug.ips[item]} ${item}<br>`;
|
||||
hotIPsValue += `${ctx.debug.ips[item]} ${item}<br>`;
|
||||
});
|
||||
|
||||
let showDebug;
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
.debug-value {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
white-space: pre;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -48,19 +48,19 @@ describe('debug', () => {
|
||||
expect(value).toBe('8');
|
||||
break;
|
||||
case 'hot routes:':
|
||||
expect(value).toBe(`7 /test/:id<br>`);
|
||||
expect(value).toBe(`7 /test/:id<br>`);
|
||||
break;
|
||||
case 'hot paths:':
|
||||
expect(value).toBe(`3 /test/1<br>2 /test/2<br>2 /test/empty<br>1 /<br>`);
|
||||
expect(value).toBe(`3 /test/1<br>2 /test/2<br>2 /test/empty<br>1 /<br>`);
|
||||
break;
|
||||
case 'hot IP:':
|
||||
expect(value).toBe(`5 233.233.233.233<br>3 233.233.233.234<br>`);
|
||||
expect(value).toBe(`5 233.233.233.233<br>3 233.233.233.234<br>`);
|
||||
break;
|
||||
case 'hot error routes:':
|
||||
expect(value).toBe(`2 /test/:id<br>`);
|
||||
expect(value).toBe(`2 /test/:id<br>`);
|
||||
break;
|
||||
case 'hot error paths:':
|
||||
expect(value).toBe(`2 /test/empty<br>`);
|
||||
expect(value).toBe(`2 /test/empty<br>`);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user