From 040a0e561b4f623f7929130b90be129f94ebb642 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Fri, 10 Sep 2021 22:23:35 +0200 Subject: [PATCH] fix: use non-deprecated tracing categories api (#7413) --- src/common/Tracing.ts | 10 +++++++++- test/tracing.spec.ts | 29 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/common/Tracing.ts b/src/common/Tracing.ts index cc0a13c295223..9a90799915539 100644 --- a/src/common/Tracing.ts +++ b/src/common/Tracing.ts @@ -87,11 +87,19 @@ export class Tracing { if (screenshots) categories.push('disabled-by-default-devtools.screenshot'); + const excludedCategories = categories + .filter((cat) => cat.startsWith('-')) + .map((cat) => cat.slice(1)); + const includedCategories = categories.filter((cat) => !cat.startsWith('-')); + this._path = path; this._recording = true; await this._client.send('Tracing.start', { transferMode: 'ReturnAsStream', - categories: categories.join(','), + traceConfig: { + excludedCategories, + includedCategories, + }, }); } diff --git a/test/tracing.spec.ts b/test/tracing.spec.ts index 5e06f12b4c9d6..80de87f3bfa23 100644 --- a/test/tracing.spec.ts +++ b/test/tracing.spec.ts @@ -56,15 +56,38 @@ describeChromeOnly('Tracing', function () { it('should run with custom categories if provided', async () => { await page.tracing.start({ path: outputFile, - categories: ['disabled-by-default-v8.cpu_profiler.hires'], + categories: ['-*', 'disabled-by-default-v8.cpu_profiler.hires'], }); await page.tracing.stop(); const traceJson = JSON.parse( fs.readFileSync(outputFile, { encoding: 'utf8' }) ); - expect(traceJson.metadata['trace-config']).toContain( - 'disabled-by-default-v8.cpu_profiler.hires' + const traceConfig = JSON.parse(traceJson.metadata['trace-config']); + expect(traceConfig.included_categories).toEqual([ + 'disabled-by-default-v8.cpu_profiler.hires', + ]); + expect(traceConfig.excluded_categories).toEqual(['*']); + expect(traceJson.traceEvents).not.toContainEqual( + expect.objectContaining({ + cat: 'toplevel', + }) + ); + }); + + it('should run with default categories', async () => { + await page.tracing.start({ + path: outputFile, + }); + await page.tracing.stop(); + + const traceJson = JSON.parse( + fs.readFileSync(outputFile, { encoding: 'utf8' }) + ); + expect(traceJson.traceEvents).toContainEqual( + expect.objectContaining({ + cat: 'toplevel', + }) ); }); it('should throw if tracing on two pages', async () => {