mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DataSourceWithBackend: Switch to new Observable fetch api (#26043)
* BackendSrv: Observable all the way POC * starting to unify code paths * tests pass * Unified error handling * Single request path and error handling * Fixed ts issue * another ts issu * Added back old requestId cancellation * Slow progress trying to grasp the full picture of cancellation * Updates * refactoring * Remove a bunch of stuff from backendSrv * Removed another function * Do not show error alerts for data queries * Muu * Updated comment * DataSourceWithBackend: Switch to new Observable fetch api * fixed ts issue * unify request options type * Made query inspector subscribe to backendSrv stream instead of legacy app events * Add back support for err.isHandled to limit scope * never show success alerts * Updated tests * use ovservable in test * remove processResponse * remove processResponse * trying to get tests to pass :( * no need for the extra tests * Fixed processsing * Fixed tests * Updated tests to mock fetch call * lint fixes Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
import 'whatwg-fetch'; // fetch polyfill needed for Headers
|
||||
|
||||
import { BackendSrvRequest, FetchResponse } from '@grafana/runtime';
|
||||
import { of } from 'rxjs';
|
||||
import { BackendSrv } from '../backend_srv';
|
||||
|
||||
/**
|
||||
* Creates a pretty bogus prom response. Definitelly needs more work but right now we do not test the contents of the
|
||||
* messages anyway.
|
||||
@@ -20,14 +26,18 @@ function makePromResponse() {
|
||||
};
|
||||
}
|
||||
|
||||
export const backendSrv = {
|
||||
export const backendSrv = ({
|
||||
get: jest.fn(),
|
||||
getDashboard: jest.fn(),
|
||||
getDashboardByUid: jest.fn(),
|
||||
getFolderByUid: jest.fn(),
|
||||
post: jest.fn(),
|
||||
resolveCancelerIfExists: jest.fn(),
|
||||
datasourceRequest: jest.fn(() => Promise.resolve(makePromResponse())),
|
||||
};
|
||||
|
||||
// Observable support
|
||||
fetch: (options: BackendSrvRequest) => {
|
||||
return of(makePromResponse() as FetchResponse);
|
||||
},
|
||||
} as unknown) as BackendSrv;
|
||||
|
||||
export const getBackendSrv = jest.fn().mockReturnValue(backendSrv);
|
||||
|
||||
Reference in New Issue
Block a user