From 18238280df7749a15767ad7eb1d4881aefb83018 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Thu, 23 Apr 2020 12:51:48 +0100 Subject: [PATCH] chore: migrate src/Tracing to TypeScript (#5723) --- src/Page.js | 2 +- src/{Tracing.js => Tracing.ts} | 41 +++++++++++-------------- src/api.js | 2 +- utils/doclint/check_public_api/index.js | 4 +++ 4 files changed, 24 insertions(+), 25 deletions(-) rename src/{Tracing.js => Tracing.ts} (75%) diff --git a/src/Page.js b/src/Page.js index 3bcc291e..77e0e564 100644 --- a/src/Page.js +++ b/src/Page.js @@ -25,7 +25,7 @@ const {Dialog} = require('./Dialog'); const {EmulationManager} = require('./EmulationManager'); const {FrameManager} = require('./FrameManager'); const {Keyboard, Mouse, Touchscreen} = require('./Input'); -const Tracing = require('./Tracing'); +const {Tracing} = require('./Tracing'); const {helper, debugError, assert} = require('./helper'); const {Coverage} = require('./Coverage'); const {Worker: PuppeteerWorker} = require('./Worker'); diff --git a/src/Tracing.js b/src/Tracing.ts similarity index 75% rename from src/Tracing.js rename to src/Tracing.ts index 2f14b374..aaa48a03 100644 --- a/src/Tracing.js +++ b/src/Tracing.ts @@ -13,25 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const {helper, assert} = require('./helper'); -// Used as a TypeDef -// eslint-disable-next-line no-unused-vars -const {CDPSession} = require('./Connection'); +import {helper, assert} from './helper'; +import {CDPSession} from './Connection'; -class Tracing { - /** - * @param {!CDPSession} client - */ - constructor(client) { +interface TracingOptions { + path?: string; + screenshots?: boolean; + categories?: string[]; +} + +export class Tracing { + _client: CDPSession; + _recording = false; + _path = ''; + + constructor(client: CDPSession) { this._client = client; - this._recording = false; - this._path = ''; } - /** - * @param {!{path?: string, screenshots?: boolean, categories?: !Array}} options - */ - async start(options = {}) { + async start(options: TracingOptions = {}): Promise { assert(!this._recording, 'Cannot start recording trace while already recording trace.'); const defaultCategories = [ @@ -57,12 +57,9 @@ class Tracing { }); } - /** - * @return {!Promise} - */ - async stop() { - let fulfill; - const contentPromise = new Promise(x => fulfill = x); + async stop(): Promise { + let fulfill: (value: Buffer) => void; + const contentPromise = new Promise(x => fulfill = x); this._client.once('Tracing.tracingComplete', event => { helper.readProtocolStream(this._client, event.stream, this._path).then(fulfill); }); @@ -71,5 +68,3 @@ class Tracing { return contentPromise; } } - -module.exports = Tracing; diff --git a/src/api.js b/src/api.js index afb0acb7..c7fdea80 100644 --- a/src/api.js +++ b/src/api.js @@ -38,6 +38,6 @@ module.exports = { Target: require('./Target').Target, TimeoutError: require('./Errors').TimeoutError, Touchscreen: require('./Input').Touchscreen, - Tracing: require('./Tracing'), + Tracing: require('./Tracing').Tracing, Worker: require('./Worker').Worker, }; diff --git a/utils/doclint/check_public_api/index.js b/utils/doclint/check_public_api/index.js index bfd6b7fa..b7e7a76c 100644 --- a/utils/doclint/check_public_api/index.js +++ b/utils/doclint/check_public_api/index.js @@ -295,6 +295,10 @@ function compareDocumentations(actual, expected) { actualName: 'Object', expectedName: 'MouseOptions' }], + ['Method Tracing.start() options', { + actualName: 'Object', + expectedName: 'TracingOptions' + }], ]); const expectedForSource = expectedNamingMismatches.get(source);