Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import {
Page,
APIRequestContext,
} from 'playwright-core';
import { Journey, Step } from './dsl';
import { APIJourney, Journey, Step } from './dsl';
import { BuiltInReporterName, ReporterInstance } from './reporters';
import { AlertConfig, MonitorConfig } from './dsl/monitor';
import { RunnerInfo } from './core/runner';
import { APIRunnerInfo } from './core/api-runner';

export type VoidCallback = () => void;
export type Location = {
Expand All @@ -57,13 +58,24 @@ export type HooksArgs = {
export type HooksCallback = (args: HooksArgs) => void;
export type StatusValue = 'pending' | 'succeeded' | 'failed' | 'skipped';

export type APIHooksArgs = {
env: string;
params: Params;
info: APIRunnerInfo;
};
export type APIHooksCallback = (args: APIHooksArgs) => void;

export type NetworkConditions = {
offline: boolean;
downloadThroughput: number;
uploadThroughput: number;
latency: number;
};

export type APIDriver = {
request: APIRequestContext;
};

export type Driver = {
browser: ChromiumBrowser;
context: ChromiumBrowserContext;
Expand Down Expand Up @@ -252,6 +264,13 @@ export type RunOptions = BaseArgs & {
grepOpts?: GrepOptions;
};

export type APIRunOptions = BaseArgs & {
network?: boolean;
environment?: string;
reporter?: BuiltInReporterName | ReporterInstance;
grepOpts?: GrepOptions;
};

export type PushOptions = Partial<ProjectSettings> &
Partial<BaseArgs> & {
auth: string;
Expand Down Expand Up @@ -285,6 +304,13 @@ export type SyntheticsConfig = {
project?: ProjectSettings;
};

/** Runner Payload types */
export type APIJourneyResult = Partial<APIJourney> & {
networkinfo?: PluginOutput['networkinfo'];
browserconsole?: PluginOutput['browserconsole'];
stepsresults?: Array<StepResult>;
};

/** Runner Payload types */
export type JourneyResult = Partial<Journey> & {
networkinfo?: PluginOutput['networkinfo'];
Expand Down Expand Up @@ -324,4 +350,10 @@ export type JourneyEndResult = JourneyStartResult &
options: RunOptions;
};

export type APIJourneyEndResult = JourneyStartResult &
APIJourneyResult & {
browserDelay: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

browserDelay is not appropriate for apijourneys?

options: RunOptions;
};

export type StepEndResult = StepResult;
85 changes: 85 additions & 0 deletions src/core/api-gatherer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* MIT License
*
* Copyright (c) 2020-present, Elastic NV
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

import { request as apiRequest } from 'playwright-core';
import { log } from './logger';
import { APIDriver, RunOptions } from '../common_types';
import { APIPluginManager } from '../plugins/api-plugin-manager';

/**
* Purpose of the Gatherer is to set up the necessary browser driver
* related capabilities for the runner to run all journeys
*/
export class APIGatherer {
static pluginManager: APIPluginManager;

static async setupDriver(options: RunOptions) {
log('Gatherer: setup browser');
const { playwrightOptions } = options;

// Register sig int handler to close the browser
process.on('SIGINT', async () => {
await APIGatherer.stop();
process.exit(130);
});

const request = await apiRequest.newContext({ ...playwrightOptions });
return { request };
}

/**
* Starts recording all events related to the v8 devtools protocol
* https://chromedevtools.github.io/devtools-protocol/v8/
*/

static async beginRecording(driver: APIDriver, options: RunOptions) {
log('Gatherer: started recording');
APIGatherer.pluginManager = new APIPluginManager(driver);
APIGatherer.pluginManager.registerAll(options);
const plugins = [];
plugins.push(await APIGatherer.pluginManager.start('network'));

await Promise.all(plugins);
return APIGatherer.pluginManager;
}

static async endRecording() {
log('Gatherer: ended recording');
await APIGatherer.pluginManager.unregisterAll();
}

static async dispose(driver: APIDriver) {
log(`Gatherer: closing all contexts`);
await driver.request.dispose();
}

static async stop() {
log(`Gatherer: closing browser`);
// if (Gatherer.request) {
// await Gatherer.browser.close();
// Gatherer.browser = null;
// }
}
}
Loading
Loading