grafana/e2e/utils/support/benchmark.ts
Ashley Harrison d8e99e2bb5
Chore: Remove more stuff from the e2e object (#75513)
* cut down the e2e object more :)

* undo changes in grafana-e2e

* couple more things to undo in grafana-e2e
2023-09-27 11:33:00 +01:00

71 lines
1.7 KiB
TypeScript

import { e2e } from '../';
export interface BenchmarkArguments {
name: string;
dashboard: {
folder: string;
delayAfterOpening: number;
skipPanelValidation: boolean;
};
repeat: number;
duration: number;
appStats?: {
startCollecting?: (window: Window) => void;
collect: (window: Window) => Record<string, unknown>;
};
skipScenario?: boolean;
}
export const benchmark = ({
name,
skipScenario = false,
repeat,
duration,
appStats,
dashboard,
}: BenchmarkArguments) => {
if (skipScenario) {
describe(name, () => {
it.skip(name, () => {});
});
} else {
describe(name, () => {
beforeEach(() => {
e2e.flows.login(Cypress.env('USERNAME'), Cypress.env('PASSWORD'));
e2e.flows.importDashboards(dashboard.folder, 1000, dashboard.skipPanelValidation);
});
afterEach(() => e2e.flows.revertAllChanges());
Array(repeat)
.fill(0)
.map((_, i) => {
const testName = `${name}-${i}`;
return it(testName, () => {
e2e.flows.openDashboard();
cy.wait(dashboard.delayAfterOpening);
if (appStats) {
const startCollecting = appStats.startCollecting;
if (startCollecting) {
cy.window().then((win) => startCollecting(win));
}
cy.startBenchmarking(testName);
cy.wait(duration);
cy.window().then((win) => {
cy.stopBenchmarking(testName, appStats.collect(win));
});
} else {
cy.startBenchmarking(testName);
cy.wait(duration);
cy.stopBenchmarking(testName, {});
}
});
});
});
}
};