Skip to content

Commit 1c358c9

Browse files
farhan-saucechristian-bromann
authored andcommitted
add new public method: getMainTrackEvents (#11)
* add new method: getMainTrackEvents * Fix lint issues * Update index.test.ts.snap
1 parent e1d1870 commit 1c358c9

4 files changed

Lines changed: 65 additions & 27 deletions

File tree

jest.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
4+
collectCoverageFrom: ['./src/**'],
45
coverageDirectory: './coverage/',
56
coverageThreshold: {
67
global: {
7-
branches: 43,
8-
functions: 68,
9-
lines: 63,
10-
statements: 63
8+
branches: 90,
9+
functions: 90,
10+
lines: 90,
11+
statements: 90
1112
}
1213
},
1314
testMatch: [

src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export default class Tracelib {
2929
))
3030
}
3131

32+
public getMainTrackEvents(): Event[] {
33+
const mainTrack = this._findMainTrack()
34+
if (!mainTrack) {
35+
throw new Error('MainTrack is missing in traceLog')
36+
}
37+
return mainTrack.events
38+
}
39+
3240
public getFPS(): number[] {
3341
return this._timelineLoader.performanceModel.frames()
3442
.map(({ duration }): number => calcFPS(duration))
@@ -38,9 +46,14 @@ export default class Tracelib {
3846
const timelineUtils = new TimelineUIUtils()
3947
const startTime = from || this._performanceModel.startTime
4048
const endTime = to || this._performanceModel.endTime
49+
const mainTrack = this._findMainTrack()
50+
if (!mainTrack) {
51+
throw new Error('MainTrack is missing in traceLog')
52+
}
53+
4154
return {
4255
...timelineUtils.statsForTimeRange(
43-
this._findMainTrack().syncEvents(), startTime, endTime
56+
mainTrack.syncEvents(), startTime, endTime
4457
),
4558
startTime,
4659
endTime,

tests/__snapshots__/index.test.ts.snap

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`getSummary: should get summary data 1`] = `
4+
Object {
5+
"endTime": 289961229.717,
6+
"idle": 52.38300037384033,
7+
"other": 9.896000564098358,
8+
"painting": 69.94999980926514,
9+
"rendering": 847.373997092247,
10+
"scripting": 394.4800021648407,
11+
"startTime": 289959855.634,
12+
}
13+
`;
14+
15+
exports[`getWarningCounts: should get warning counts 1`] = `
16+
Object {
17+
"ForcedLayout": 4683,
18+
"ForcedStyle": 4684,
19+
"LongRecurringHandler": 13,
20+
}
21+
`;
22+
323
exports[`should get FPS 1`] = `
424
Array [
525
182.2821727559685,
@@ -100,18 +120,6 @@ Object {
100120
}
101121
`;
102122

103-
exports[`should get summary data 1`] = `
104-
Object {
105-
"endTime": 289961229.717,
106-
"idle": 52.38300037384033,
107-
"other": 9.896000564098358,
108-
"painting": 69.94999980926514,
109-
"rendering": 847.373997092247,
110-
"scripting": 394.4800021648407,
111-
"startTime": 289959855.634,
112-
}
113-
`;
114-
115123
exports[`should get summary data between passed range 1`] = `
116124
Object {
117125
"endTime": 289960729.717,
@@ -123,11 +131,3 @@ Object {
123131
"startTime": 289960055.634,
124132
}
125133
`;
126-
127-
exports[`should get warning counts 1`] = `
128-
Object {
129-
"ForcedLayout": 4683,
130-
"ForcedStyle": 4684,
131-
"LongRecurringHandler": 13,
132-
}
133-
`;

tests/index.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,50 @@ test('should get FPS', () => {
1212
expect(result).toMatchSnapshot()
1313
})
1414

15-
test('should get summary data', () => {
15+
test('getSummary: should get summary data', () => {
1616
const trace = new Tracelib(JANK_TRACE_LOG)
1717
const result = trace.getSummary()
1818
expect(result).toMatchSnapshot()
1919
})
2020

21+
test('getSummary: should throw error if main track is missing', () => {
22+
const trace = new Tracelib([])
23+
expect(() => trace.getSummary())
24+
.toThrow(new Error('MainTrack is missing in traceLog'))
25+
})
26+
2127
test('should get summary data between passed range', () => {
2228
const trace = new Tracelib(JANK_TRACE_LOG)
2329
const result = trace.getSummary(289960055.634, 289960729.717)
2430
expect(result).toMatchSnapshot()
2531
})
2632

27-
test('should get warning counts', () => {
33+
test('getWarningCounts: should get warning counts', () => {
2834
const trace = new Tracelib(JANK_TRACE_LOG)
2935
const result = trace.getWarningCounts()
3036
expect(result).toMatchSnapshot()
3137
})
3238

39+
test('getWarningCounts: should throw error if main track is missing', () => {
40+
const trace = new Tracelib([])
41+
expect(() => trace.getWarningCounts())
42+
.toThrow(new Error('MainTrack is missing in traceLog'))
43+
})
44+
3345
test('should get memory counters', () => {
3446
const trace = new Tracelib(JANK_TRACE_LOG)
3547
const result = trace.getMemoryCounters()
3648
expect(result).toMatchSnapshot()
3749
})
50+
51+
test('mainTrackEvents: should get events', () => {
52+
const trace = new Tracelib(JANK_TRACE_LOG)
53+
const result = trace.getMainTrackEvents()
54+
expect(result.length).toEqual(56244)
55+
})
56+
57+
test('mainTrackEvents: should throws error if main track is missing', () => {
58+
const trace = new Tracelib([])
59+
expect(() => trace.getMainTrackEvents())
60+
.toThrow(new Error('MainTrack is missing in traceLog'))
61+
})

0 commit comments

Comments
 (0)