test: fix debug test case

This commit is contained in:
DIYgod
2019-09-04 21:56:16 +08:00
parent 4bc0a56064
commit 16263b020c
5 changed files with 24 additions and 10 deletions
+2
View File
@@ -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;
};
+11
View File
@@ -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
View File
@@ -19,14 +19,14 @@ module.exports = async (ctx) => {
const hotRoutes = routes.slice(0, 30);
let hotRoutesValue = '';
hotRoutes.forEach((item) => {
hotRoutesValue += `${ctx.debug.routes[item]}&nbsp;&nbsp;${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]}&nbsp;&nbsp;${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]}&nbsp;&nbsp;${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]}&nbsp;&nbsp;${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]}&nbsp;&nbsp;${item}<br>`;
hotIPsValue += `${ctx.debug.ips[item]} ${item}<br>`;
});
let showDebug;
+1
View File
@@ -65,6 +65,7 @@
.debug-value {
display: inline-block;
vertical-align: top;
white-space: pre;
}
</style>
</head>
+5 -5
View File
@@ -48,19 +48,19 @@ describe('debug', () => {
expect(value).toBe('8');
break;
case 'hot routes:':
expect(value).toBe(`7&nbsp;&nbsp;/test/:id<br>`);
expect(value).toBe(`7 /test/:id<br>`);
break;
case 'hot paths:':
expect(value).toBe(`3&nbsp;&nbsp;/test/1<br>2&nbsp;&nbsp;/test/2<br>2&nbsp;&nbsp;/test/empty<br>1&nbsp;&nbsp;/<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&nbsp;&nbsp;233.233.233.233<br>3&nbsp;&nbsp;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&nbsp;&nbsp;/test/:id<br>`);
expect(value).toBe(`2 /test/:id<br>`);
break;
case 'hot error paths:':
expect(value).toBe(`2&nbsp;&nbsp;/test/empty<br>`);
expect(value).toBe(`2 /test/empty<br>`);
break;
}
});