Commit 387f7c3d authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '33909-show-peek-ajax-api-requests' into 'master'

Automatically add AJAX requests to API endpoints in the performance bar

See merge request gitlab-org/gitlab!39069
parents 857bd5dc 47f1894d
......@@ -32,10 +32,9 @@ export default class PerformanceBarService {
// Get the request URL from response.config for Axios, and response for
// Vue Resource.
const requestUrl = (response.config || response).url;
const apiRequest = requestUrl && requestUrl.match(/^\/api\//);
const cachedResponse =
response.headers && parseBoolean(response.headers['x-gitlab-from-cache']);
const fireCallback = requestUrl !== peekUrl && requestId && !apiRequest && !cachedResponse;
const fireCallback = requestUrl !== peekUrl && Boolean(requestId) && !cachedResponse;
return [fireCallback, requestId, requestUrl];
}
......
---
title: Automatically add AJAX API requests to the performance bar
merge_request: 39069
author:
type: added
......@@ -8,19 +8,13 @@ describe('PerformanceBarService', () => {
}
it('returns false when the request URL is the peek URL', () => {
expect(
fireCallback({ headers: { 'x-request-id': '123' }, url: '/peek' }, '/peek'),
).toBeFalsy();
expect(fireCallback({ headers: { 'x-request-id': '123' }, url: '/peek' }, '/peek')).toBe(
false,
);
});
it('returns false when there is no request ID', () => {
expect(fireCallback({ headers: {}, url: '/request' }, '/peek')).toBeFalsy();
});
it('returns false when the request is an API request', () => {
expect(
fireCallback({ headers: { 'x-request-id': '123' }, url: '/api/' }, '/peek'),
).toBeFalsy();
expect(fireCallback({ headers: {}, url: '/request' }, '/peek')).toBe(false);
});
it('returns false when the response is from the cache', () => {
......@@ -29,13 +23,19 @@ describe('PerformanceBarService', () => {
{ headers: { 'x-request-id': '123', 'x-gitlab-from-cache': 'true' }, url: '/request' },
'/peek',
),
).toBeFalsy();
).toBe(false);
});
it('returns true when all conditions are met', () => {
expect(
fireCallback({ headers: { 'x-request-id': '123' }, url: '/request' }, '/peek'),
).toBeTruthy();
it('returns true when the request is an API request', () => {
expect(fireCallback({ headers: { 'x-request-id': '123' }, url: '/api/' }, '/peek')).toBe(
true,
);
});
it('returns true for all other requests', () => {
expect(fireCallback({ headers: { 'x-request-id': '123' }, url: '/request' }, '/peek')).toBe(
true,
);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment