Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate src/Tracing to TypeScript #5723

Merged
merged 1 commit into from Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Page.js
Expand Up @@ -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');
Expand Down
41 changes: 18 additions & 23 deletions src/Tracing.js → src/Tracing.ts
Expand Up @@ -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<string>}} options
*/
async start(options = {}) {
async start(options: TracingOptions = {}): Promise<void> {
assert(!this._recording, 'Cannot start recording trace while already recording trace.');

const defaultCategories = [
Expand All @@ -57,12 +57,9 @@ class Tracing {
});
}

/**
* @return {!Promise<!Buffer>}
*/
async stop() {
let fulfill;
const contentPromise = new Promise(x => fulfill = x);
async stop(): Promise<Buffer> {
let fulfill: (value: Buffer) => void;
const contentPromise = new Promise<Buffer>(x => fulfill = x);
this._client.once('Tracing.tracingComplete', event => {
helper.readProtocolStream(this._client, event.stream, this._path).then(fulfill);
});
Expand All @@ -71,5 +68,3 @@ class Tracing {
return contentPromise;
}
}

module.exports = Tracing;
2 changes: 1 addition & 1 deletion src/api.js
Expand Up @@ -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,
};
4 changes: 4 additions & 0 deletions utils/doclint/check_public_api/index.js
Expand Up @@ -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);
Expand Down