From 984e011cf01c513fb586fc04ef45242b3534bb5c Mon Sep 17 00:00:00 2001 From: JoelEinbinder Date: Wed, 2 Aug 2017 15:41:05 -0700 Subject: [PATCH] Move path option into tracing.start (#192) This consolidates all the tracing options in the tracing.start() --- docs/api.md | 14 +++++++------- lib/Tracing.js | 12 +++++++----- test/test.js | 10 +++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/api.md b/docs/api.md index 9ac894563f6..227bcdc69e7 100644 --- a/docs/api.md +++ b/docs/api.md @@ -73,8 +73,8 @@ + [mouse.move(x, y)](#mousemovex-y) + [mouse.up([options])](#mouseupoptions) * [class: Tracing](#class-tracing) - + [tracing.start([options])](#tracingstartoptions) - + [tracing.stop(path)](#tracingstoppath) + + [tracing.start(options)](#tracingstartoptions) + + [tracing.stop()](#tracingstop) * [class: Dialog](#class-dialog) + [dialog.accept([promptText])](#dialogacceptprompttext) + [dialog.dismiss()](#dialogdismiss) @@ -839,18 +839,18 @@ Dispatches a `mouseup` event. You can use [`tracing.start`](#tracingstartoptions) and [`tracing.stop`](#tracingstoppath) to create a trace file which can be opened in Chrome DevTools or [timeline viewer](https://chromedevtools.github.io/timeline-viewer/). ```js -await page.tracing.start(); +await page.tracing.start({path: 'trace.json'}); await page.navigate('https://www.google.com'); -await page.tracing.stop('trace.json'); +await page.tracing.stop(); ``` -#### tracing.start([options]) +#### tracing.start(options) - `options` <[Object]> + - `path` <[string]> A path to write the trace file to. **required** - `screenshots` <[boolean]> captures screenshots in the trace. - returns: <[Promise]> -#### tracing.stop(path) -- `path` <[string]> A path to write the trace file to. +#### tracing.stop() - returns: <[Promise]> ### class: Dialog diff --git a/lib/Tracing.js b/lib/Tracing.js index f82b319dbd3..06b6c234fb4 100644 --- a/lib/Tracing.js +++ b/lib/Tracing.js @@ -23,14 +23,16 @@ class Tracing { constructor(client) { this._client = client; this._recording = false; + this._path = ''; } /** - * @param {Object=} options + * @param {!Object} options * @return {!Promise} */ - async start(options = {}) { + async start(options) { console.assert(!this._recording, 'Cannot start recording trace while already recording trace.'); + console.assert(options.path, 'Must specify a path to write trace file to.'); const categoriesArray = [ '-*', 'devtools.timeline', 'v8.execute', 'disabled-by-default-devtools.timeline', @@ -42,6 +44,7 @@ class Tracing { if (options.screenshots) categoriesArray.push('disabled-by-default-devtools.screenshot'); + this._path = options.path; this._recording = true; await this._client.send('Tracing.start', { transferMode: 'ReturnAsStream', @@ -50,14 +53,13 @@ class Tracing { } /** - * @param {string} path * @return {!Promise} */ - async stop(path) { + async stop() { let fulfill; let contentPromise = new Promise(x => fulfill = x); this._client.once('Tracing.tracingComplete', event => { - this._readStream(event.stream, path).then(fulfill); + this._readStream(event.stream, this._path).then(fulfill); }); await this._client.send('Tracing.end'); this._recording = false; diff --git a/test/test.js b/test/test.js index b7653cb0d20..2b3a3a7693c 100644 --- a/test/test.js +++ b/test/test.js @@ -1503,23 +1503,23 @@ describe('Page', function() { fs.unlinkSync(outputFile); }); it('should output a trace', SX(async function() { - await page.tracing.start({screenshots: true}); + await page.tracing.start({screenshots: true, path: outputFile}); await page.navigate(PREFIX + '/grid.html'); - await page.tracing.stop(outputFile); + await page.tracing.stop(); expect(fs.existsSync(outputFile)).toBe(true); })); it('should throw if tracing on two pages', SX(async function() { - await page.tracing.start(); + await page.tracing.start({path: outputFile}); let newPage = await browser.newPage(); let error = null; try { - await newPage.tracing.start(); + await newPage.tracing.start({path: outputFile}); } catch (e) { error = e; } await newPage.close(); expect(error).toBeTruthy(); - await page.tracing.stop(outputFile); + await page.tracing.stop(); })); }); });