* Executes only the new trace engine on the fixture and returns the resulting parsed data. * * @param context The Mocha test context. Processing a trace can easily * takes up longer than the default Mocha timeout, which is 2s. So we have to * increase this test's timeout. It might be nul
(
context: Mocha.Context|Mocha.Suite|null, name: string,
config: Trace.Types.Configuration.Configuration = Trace.Types.Configuration.defaults(), opts = {
withTimelinePanel: true,
})
| 144 | * will fall back to the Default config if not provided. |
| 145 | */ |
| 146 | static async traceEngine( |
| 147 | context: Mocha.Context|Mocha.Suite|null, name: string, |
| 148 | config: Trace.Types.Configuration.Configuration = Trace.Types.Configuration.defaults(), opts = { |
| 149 | withTimelinePanel: true, |
| 150 | }): Promise<Trace.TraceModel.ParsedTrace> { |
| 151 | if (context) { |
| 152 | TraceLoader.setTestTimeout(context); |
| 153 | } |
| 154 | let timelineModule: typeof Timeline|undefined; |
| 155 | if (opts.withTimelinePanel) { |
| 156 | timelineModule = await import('../panels/timeline/timeline.js'); |
| 157 | } |
| 158 | // Force the TraceBounds to be reset to empty. This ensures that in |
| 159 | // tests where we are using the new engine data we don't accidentally |
| 160 | // rely on the fact that a previous test has set the BoundsManager. |
| 161 | TraceBounds.TraceBounds.BoundsManager.instance({forceNew: true}); |
| 162 | |
| 163 | const configCacheKey = Trace.Types.Configuration.configToCacheKey(config); |
| 164 | |
| 165 | const fromCache = traceEngineCache.get(name)?.get(configCacheKey); |
| 166 | |
| 167 | // If we have results from the cache, we use those to ensure we keep the |
| 168 | // tests speedy and don't re-parse trace files over and over again. |
| 169 | if (fromCache) { |
| 170 | const parsedTrace = fromCache.parsedTrace; |
| 171 | await wrapInTimeout(context, () => { |
| 172 | const syntheticEventsManager = fromCache.model.syntheticTraceEventsManager(0); |
| 173 | if (!syntheticEventsManager) { |
| 174 | throw new Error('Cached trace engine result did not have a synthetic events manager instance'); |
| 175 | } |
| 176 | Trace.Helpers.SyntheticEvents.SyntheticEventsManager.activate(syntheticEventsManager); |
| 177 | TraceLoader.initTraceBoundsManager(parsedTrace); |
| 178 | if (timelineModule) { |
| 179 | timelineModule.ModificationsManager.ModificationsManager.reset(); |
| 180 | timelineModule.ModificationsManager.ModificationsManager.initAndActivateModificationsManager( |
| 181 | fromCache.model, 0); |
| 182 | } |
| 183 | }, 4_000, 'Initializing state for cached trace'); |
| 184 | return parsedTrace; |
| 185 | } |
| 186 | |
| 187 | const fileContents = await wrapInTimeout(context, async () => { |
| 188 | return await TraceLoader.fixtureContents(context, name); |
| 189 | }, 30_000, `Loading fixtureContents for ${name}`); |
| 190 | |
| 191 | const parsedTraceFileAndModel = await wrapInTimeout(context, async () => { |
| 192 | return await TraceLoader.executeTraceEngineOnFileContents( |
| 193 | fileContents, /* emulate fresh recording */ false, config); |
| 194 | }, 30_000, `Executing traceEngine for ${name}`); |
| 195 | |
| 196 | const cacheByName = traceEngineCache.get(name) ?? new Map<string, ParsedTraceAndModel>(); |
| 197 | cacheByName.set(configCacheKey, parsedTraceFileAndModel); |
| 198 | traceEngineCache.set(name, cacheByName); |
| 199 | |
| 200 | TraceLoader.initTraceBoundsManager(parsedTraceFileAndModel.parsedTrace); |
| 201 | if (timelineModule) { |
| 202 | await wrapInTimeout(context, () => { |
| 203 | timelineModule.ModificationsManager.ModificationsManager.reset(); |