Stop storing device logs on the device object and in the plugin
Summary: Logs were stored hardcoded on the Device object first, this diff makes it normal plugin state. This makes sure that we can use the same abstractions as in all plugins that store large data sets, and that we can leverage the upcoming DataSource abstraction. Reviewed By: nikoant Differential Revision: D26127243 fbshipit-source-id: 7c386a615fa7989f35ba0df5b7c1d218d37b57a2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f2ade40239
commit
7cc55daf34
@@ -7,8 +7,10 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {sleep, TestUtils} from 'flipper-plugin';
|
||||
import {addEntriesToState, processEntry} from '../index';
|
||||
import {DeviceLogEntry} from 'flipper';
|
||||
import * as LogsPlugin from '../index';
|
||||
|
||||
const entry: DeviceLogEntry = {
|
||||
tag: 'OpenGLRenderer',
|
||||
@@ -83,3 +85,70 @@ test('addEntriesToState with reversed direction (add to front)', () => {
|
||||
expect(newState.entries.length).toBe(2);
|
||||
expect(newState.rows.length).toBe(2);
|
||||
});
|
||||
|
||||
test('export / import plugin does work', async () => {
|
||||
const {
|
||||
instance,
|
||||
exportStateAsync,
|
||||
sendLogEntry,
|
||||
} = TestUtils.startDevicePlugin(LogsPlugin);
|
||||
|
||||
sendLogEntry({
|
||||
date: new Date(1611854112859),
|
||||
message: 'test1',
|
||||
pid: 0,
|
||||
tag: 'test',
|
||||
tid: 1,
|
||||
type: 'error',
|
||||
app: 'X',
|
||||
});
|
||||
sendLogEntry({
|
||||
date: new Date(1611854117859),
|
||||
message: 'test2',
|
||||
pid: 2,
|
||||
tag: 'test',
|
||||
tid: 3,
|
||||
type: 'warn',
|
||||
app: 'Y',
|
||||
});
|
||||
|
||||
// batching and storage is async atm
|
||||
await sleep(500);
|
||||
|
||||
const data = await exportStateAsync();
|
||||
expect(data).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"logs": Array [
|
||||
Object {
|
||||
"app": "X",
|
||||
"date": 1611854112859,
|
||||
"message": "test1",
|
||||
"pid": 0,
|
||||
"tag": "test",
|
||||
"tid": 1,
|
||||
"type": "error",
|
||||
},
|
||||
Object {
|
||||
"app": "Y",
|
||||
"date": 1611854117859,
|
||||
"message": "test2",
|
||||
"pid": 2,
|
||||
"tag": "test",
|
||||
"tid": 3,
|
||||
"type": "warn",
|
||||
},
|
||||
],
|
||||
}
|
||||
`);
|
||||
|
||||
expect(instance.rows.get().length).toBe(2);
|
||||
|
||||
// Run a second import
|
||||
{
|
||||
const {exportStateAsync} = TestUtils.startDevicePlugin(LogsPlugin, {
|
||||
initialState: data,
|
||||
});
|
||||
|
||||
expect(await exportStateAsync()).toEqual(data);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user