chore: migrate src/Tracing to TypeScript (#5723)
This commit is contained in:
parent
3050196d81
commit
18238280df
@ -25,7 +25,7 @@ const {Dialog} = require('./Dialog');
|
|||||||
const {EmulationManager} = require('./EmulationManager');
|
const {EmulationManager} = require('./EmulationManager');
|
||||||
const {FrameManager} = require('./FrameManager');
|
const {FrameManager} = require('./FrameManager');
|
||||||
const {Keyboard, Mouse, Touchscreen} = require('./Input');
|
const {Keyboard, Mouse, Touchscreen} = require('./Input');
|
||||||
const Tracing = require('./Tracing');
|
const {Tracing} = require('./Tracing');
|
||||||
const {helper, debugError, assert} = require('./helper');
|
const {helper, debugError, assert} = require('./helper');
|
||||||
const {Coverage} = require('./Coverage');
|
const {Coverage} = require('./Coverage');
|
||||||
const {Worker: PuppeteerWorker} = require('./Worker');
|
const {Worker: PuppeteerWorker} = require('./Worker');
|
||||||
|
@ -13,25 +13,25 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
const {helper, assert} = require('./helper');
|
import {helper, assert} from './helper';
|
||||||
// Used as a TypeDef
|
import {CDPSession} from './Connection';
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
const {CDPSession} = require('./Connection');
|
|
||||||
|
|
||||||
class Tracing {
|
interface TracingOptions {
|
||||||
/**
|
path?: string;
|
||||||
* @param {!CDPSession} client
|
screenshots?: boolean;
|
||||||
*/
|
categories?: string[];
|
||||||
constructor(client) {
|
}
|
||||||
|
|
||||||
|
export class Tracing {
|
||||||
|
_client: CDPSession;
|
||||||
|
_recording = false;
|
||||||
|
_path = '';
|
||||||
|
|
||||||
|
constructor(client: CDPSession) {
|
||||||
this._client = client;
|
this._client = client;
|
||||||
this._recording = false;
|
|
||||||
this._path = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async start(options: TracingOptions = {}): Promise<void> {
|
||||||
* @param {!{path?: string, screenshots?: boolean, categories?: !Array<string>}} options
|
|
||||||
*/
|
|
||||||
async start(options = {}) {
|
|
||||||
assert(!this._recording, 'Cannot start recording trace while already recording trace.');
|
assert(!this._recording, 'Cannot start recording trace while already recording trace.');
|
||||||
|
|
||||||
const defaultCategories = [
|
const defaultCategories = [
|
||||||
@ -57,12 +57,9 @@ class Tracing {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async stop(): Promise<Buffer> {
|
||||||
* @return {!Promise<!Buffer>}
|
let fulfill: (value: Buffer) => void;
|
||||||
*/
|
const contentPromise = new Promise<Buffer>(x => fulfill = x);
|
||||||
async stop() {
|
|
||||||
let fulfill;
|
|
||||||
const contentPromise = new Promise(x => fulfill = x);
|
|
||||||
this._client.once('Tracing.tracingComplete', event => {
|
this._client.once('Tracing.tracingComplete', event => {
|
||||||
helper.readProtocolStream(this._client, event.stream, this._path).then(fulfill);
|
helper.readProtocolStream(this._client, event.stream, this._path).then(fulfill);
|
||||||
});
|
});
|
||||||
@ -71,5 +68,3 @@ class Tracing {
|
|||||||
return contentPromise;
|
return contentPromise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Tracing;
|
|
@ -38,6 +38,6 @@ module.exports = {
|
|||||||
Target: require('./Target').Target,
|
Target: require('./Target').Target,
|
||||||
TimeoutError: require('./Errors').TimeoutError,
|
TimeoutError: require('./Errors').TimeoutError,
|
||||||
Touchscreen: require('./Input').Touchscreen,
|
Touchscreen: require('./Input').Touchscreen,
|
||||||
Tracing: require('./Tracing'),
|
Tracing: require('./Tracing').Tracing,
|
||||||
Worker: require('./Worker').Worker,
|
Worker: require('./Worker').Worker,
|
||||||
};
|
};
|
||||||
|
@ -295,6 +295,10 @@ function compareDocumentations(actual, expected) {
|
|||||||
actualName: 'Object',
|
actualName: 'Object',
|
||||||
expectedName: 'MouseOptions'
|
expectedName: 'MouseOptions'
|
||||||
}],
|
}],
|
||||||
|
['Method Tracing.start() options', {
|
||||||
|
actualName: 'Object',
|
||||||
|
expectedName: 'TracingOptions'
|
||||||
|
}],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const expectedForSource = expectedNamingMismatches.get(source);
|
const expectedForSource = expectedNamingMismatches.get(source);
|
||||||
|
Loading…
Reference in New Issue
Block a user