Fix for plugin failures showing up as platform failures
Summary: This got broken during TS migration. Plugin failures were being logged as platform failures, and showing up in the wrong graphs. Reviewed By: passy Differential Revision: D18059046 fbshipit-source-id: 8209a0e852f62e221bf64cb5091115e3cac09fd9
This commit is contained in:
committed by
Facebook Github Bot
parent
a77064ad84
commit
d350e1b339
@@ -56,7 +56,8 @@
|
||||
],
|
||||
"moduleNameMapper": {
|
||||
"^flipper$": "<rootDir>/src/index.tsx"
|
||||
}
|
||||
},
|
||||
"clearMocks": true
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest-runner/electron": "^2.0.1",
|
||||
|
||||
@@ -9,7 +9,16 @@
|
||||
|
||||
import {Store} from '../../reducers/index';
|
||||
import {getStringFromErrorLike} from '../../utils/errors';
|
||||
import {Args, Logger, TrackType} from '../../fb-interfaces/Logger';
|
||||
import {Args, Logger} from '../../fb-interfaces/Logger';
|
||||
|
||||
const instance = {
|
||||
track: jest.fn(),
|
||||
trackTimeSince: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
error: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
};
|
||||
|
||||
export function extractError(
|
||||
...data: Array<any>
|
||||
@@ -22,30 +31,10 @@ export function extractError(
|
||||
};
|
||||
}
|
||||
|
||||
export class FBLogger implements Logger {
|
||||
constructor(_store?: Store, _args?: Args) {}
|
||||
|
||||
track(_type: TrackType, _event: string, _data?: any, _plugin?: string) {}
|
||||
|
||||
trackTimeSince(_mark: string, _eventName?: string) {}
|
||||
|
||||
info = (..._data: Array<any>) => {};
|
||||
|
||||
warn = (..._data: Array<any>) => {};
|
||||
|
||||
error = (..._data: Array<any>) => {};
|
||||
|
||||
debug = (..._data: Array<any>) => {};
|
||||
|
||||
getLogs(): Array<string> {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function init(_store: Store, _args?: Args): Logger {
|
||||
return new FBLogger();
|
||||
return instance;
|
||||
}
|
||||
|
||||
export function getInstance(): Logger {
|
||||
return new FBLogger();
|
||||
return instance;
|
||||
}
|
||||
|
||||
146
src/utils/__tests__/metrics.node.tsx
Normal file
146
src/utils/__tests__/metrics.node.tsx
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
jest.mock('../../fb-stubs/Logger');
|
||||
try {
|
||||
jest.mock('../../fb/Logger');
|
||||
} catch {
|
||||
// Allowed to fail when fb modules are not present.
|
||||
}
|
||||
|
||||
import {reportPlatformFailures, reportPluginFailures} from '../metrics';
|
||||
import {getInstance} from '../../fb/Logger';
|
||||
import {CancelledPromiseError} from '../errors';
|
||||
import {mocked} from 'ts-jest/utils';
|
||||
|
||||
const logger = mocked(getInstance());
|
||||
|
||||
test('reportPlatformFailures logs failures correctly', async () => {
|
||||
await reportPlatformFailures(
|
||||
Promise.reject(new Error('Broken Feature')),
|
||||
'test-event',
|
||||
).catch(() => {
|
||||
// This is expected to throw
|
||||
});
|
||||
|
||||
expect(logger.track.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"success-rate",
|
||||
"test-event",
|
||||
Object {
|
||||
"error": "Broken Feature",
|
||||
"supportedOperation": 1,
|
||||
"value": 0,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('reportPlatformFailures logs cancelled operations correctly', async () => {
|
||||
await reportPlatformFailures(
|
||||
Promise.reject(new CancelledPromiseError('Operation cancelled')),
|
||||
'test-event',
|
||||
).catch(() => {
|
||||
// This is expected to throw
|
||||
});
|
||||
|
||||
expect(logger.track.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"operation-cancelled",
|
||||
"test-event",
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('reportPlatformFailures logs success correctly', async () => {
|
||||
await reportPlatformFailures(Promise.resolve('woohoo!'), 'test-event');
|
||||
|
||||
expect(logger.track.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"success-rate",
|
||||
"test-event",
|
||||
Object {
|
||||
"value": 1,
|
||||
},
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('reportPluginFailures logs failures correctly', async () => {
|
||||
await reportPluginFailures(
|
||||
Promise.reject(new Error('Broken Feature')),
|
||||
'test-event',
|
||||
'test-plugin',
|
||||
).catch(() => {
|
||||
// This is expected to throw
|
||||
});
|
||||
|
||||
expect(logger.track.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"success-rate",
|
||||
"test-event",
|
||||
Object {
|
||||
"error": "Broken Feature",
|
||||
"supportedOperation": 1,
|
||||
"value": 0,
|
||||
},
|
||||
"test-plugin",
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('reportPluginFailures logs cancelled operations correctly', async () => {
|
||||
await reportPluginFailures(
|
||||
Promise.reject(new CancelledPromiseError('Operation cancelled')),
|
||||
'test-event',
|
||||
'test-plugin',
|
||||
).catch(() => {
|
||||
// This is expected to throw
|
||||
});
|
||||
|
||||
expect(logger.track.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"operation-cancelled",
|
||||
"test-event",
|
||||
undefined,
|
||||
"test-plugin",
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('reportPluginFailures logs success correctly', async () => {
|
||||
await reportPluginFailures(
|
||||
Promise.resolve('woohoo!'),
|
||||
'test-event',
|
||||
'test-plugin',
|
||||
);
|
||||
|
||||
expect(logger.track.mock.calls).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Array [
|
||||
"success-rate",
|
||||
"test-event",
|
||||
Object {
|
||||
"value": 1,
|
||||
},
|
||||
"test-plugin",
|
||||
],
|
||||
]
|
||||
`);
|
||||
});
|
||||
@@ -73,11 +73,11 @@ export function reportPluginFailures<T>(
|
||||
},
|
||||
rejectionReason => {
|
||||
if (rejectionReason instanceof CancelledPromiseError) {
|
||||
logPlatformSuccessRate(name, {
|
||||
logPluginSuccessRate(name, plugin, {
|
||||
kind: 'cancelled',
|
||||
});
|
||||
} else {
|
||||
logPlatformSuccessRate(name, {
|
||||
logPluginSuccessRate(name, plugin, {
|
||||
kind: 'failure',
|
||||
supportedOperation: !(rejectionReason instanceof UnsupportedError),
|
||||
error: rejectionReason,
|
||||
|
||||
Reference in New Issue
Block a user