Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export default class Tracelib {
throw new Error('MainTrack is missing in traceLog')
}

// We are facing data mutaion issue in devtools, to avoid it cloning syncEvents
const syncEvents = mainTrack.syncEvents().slice()

return {
...timelineUtils.statsForTimeRange(
mainTrack.syncEvents(), startTime, endTime
syncEvents, startTime, endTime
),
startTime,
endTime,
Expand Down
40 changes: 26 additions & 14 deletions tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getSummary: should get summary data 1`] = `
exports[`getSummary should get summary data 1`] = `
Object {
"endTime": 289961229.717,
"idle": 52.38300037384033,
Expand All @@ -12,7 +12,31 @@ Object {
}
`;

exports[`getWarningCounts: should get warning counts 1`] = `
exports[`getSummary should get summary data between passed range 1`] = `
Object {
"endTime": 289960729.717,
"idle": 0.6339998841285706,
"other": 4.653000295162201,
"painting": 34.8999999165535,
"rendering": 425.89399832487106,
"scripting": 208.0020015835762,
"startTime": 289960055.634,
}
`;

exports[`getSummary should not throw error on second call of getSummary 1`] = `
Object {
"endTime": 289961229.717,
"idle": 52.38300037384033,
"other": 9.896000564098358,
"painting": 69.94999980926514,
"rendering": 847.373997092247,
"scripting": 394.4800021648407,
"startTime": 289959855.634,
}
`;

exports[`getWarningCounts should get warning counts 1`] = `
Object {
"ForcedLayout": 4683,
"ForcedStyle": 4684,
Expand Down Expand Up @@ -119,15 +143,3 @@ Object {
},
}
`;

exports[`should get summary data between passed range 1`] = `
Object {
"endTime": 289960729.717,
"idle": 0.6339998841285706,
"other": 4.653000295162201,
"painting": 34.8999999165535,
"rendering": 425.89399832487106,
"scripting": 208.0020015835762,
"startTime": 289960055.634,
}
`;
80 changes: 45 additions & 35 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,71 @@
import Tracelib from '../src/index'
import JANK_TRACE_LOG from './__fixtures__/jankTraceLog.json'

let trace: Tracelib
beforeAll(() => {
trace = new Tracelib(JANK_TRACE_LOG)
})

test('should contain traceLog', () => {
const sampleTrace = new Tracelib({ foo: 'bar' })
expect(sampleTrace.tracelog).toEqual({ foo: 'bar' })
})

test('should get FPS', () => {
const trace = new Tracelib(JANK_TRACE_LOG)
const result = trace.getFPS()
expect(result).toMatchSnapshot()
})

test('getSummary: should get summary data', () => {
const trace = new Tracelib(JANK_TRACE_LOG)
const result = trace.getSummary()
expect(result).toMatchSnapshot()
})
describe('getSummary', () => {
it('should get summary data', () => {
const result = trace.getSummary()
expect(result).toMatchSnapshot()
})

test('getSummary: should throw error if main track is missing', () => {
const trace = new Tracelib([])
expect(() => trace.getSummary())
.toThrow(new Error('MainTrack is missing in traceLog'))
})
it('should not throw error on second call of getSummary', () => {
const result = trace.getSummary()
expect(result).toMatchSnapshot()
})

test('should get summary data between passed range', () => {
const trace = new Tracelib(JANK_TRACE_LOG)
const result = trace.getSummary(289960055.634, 289960729.717)
expect(result).toMatchSnapshot()
})
it('should throw error if main track is missing', () => {
const tracelib = new Tracelib([])
expect(() => tracelib.getSummary())
.toThrow(new Error('MainTrack is missing in traceLog'))
})

test('getWarningCounts: should get warning counts', () => {
const trace = new Tracelib(JANK_TRACE_LOG)
const result = trace.getWarningCounts()
expect(result).toMatchSnapshot()
it('should get summary data between passed range', () => {
const result = trace.getSummary(289960055.634, 289960729.717)
expect(result).toMatchSnapshot()
})
})

test('getWarningCounts: should throw error if main track is missing', () => {
const trace = new Tracelib([])
expect(() => trace.getWarningCounts())
.toThrow(new Error('MainTrack is missing in traceLog'))
describe('getWarningCounts', () => {
it('should get warning counts', () => {
const result = trace.getWarningCounts()
expect(result).toMatchSnapshot()
})

it('should throw error if main track is missing', () => {
const tracelib = new Tracelib([])
expect(() => tracelib.getWarningCounts())
.toThrow(new Error('MainTrack is missing in traceLog'))
})
})

test('should get memory counters', () => {
const trace = new Tracelib(JANK_TRACE_LOG)
const result = trace.getMemoryCounters()
expect(result).toMatchSnapshot()
})

test('mainTrackEvents: should get events', () => {
const trace = new Tracelib(JANK_TRACE_LOG)
const result = trace.getMainTrackEvents()
expect(result.length).toEqual(56244)
})
describe('mainTrackEvents', () => {
it('should get events', () => {
const result = trace.getMainTrackEvents()
expect(result.length).toEqual(56244)
})

test('mainTrackEvents: should throws error if main track is missing', () => {
const trace = new Tracelib([])
expect(() => trace.getMainTrackEvents())
.toThrow(new Error('MainTrack is missing in traceLog'))
})
it('should throws error if main track is missing', () => {
const tracelib = new Tracelib([])
expect(() => tracelib.getMainTrackEvents())
.toThrow(new Error('MainTrack is missing in traceLog'))
})
})