mattermost/e2e-tests/cypress/tests/utils/benchmark.js
Harrison Healey 8533350a91
MM-61893 Replace usage of hasOwnProperty with Object.hasOwn (#29428)
* MM-61893 Replace usage of hasOwnProperty with Object.hasOwn

* Update type guard in messageToElement

* Replace a couple more hasOwnProperty calls
2024-12-03 21:53:23 +00:00

29 lines
1,006 B
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
export function reportBenchmarkResults(cy, win) {
const testName = getTestName();
const selectors = win.getSortedTrackedSelectors();
win.dumpTrackedSelectorsStatistics();
cy.log(selectors.length);
cy.writeFile(`tests/integration/benchmark/__benchmarks__/${testName}.json`, JSON.stringify(selectors));
}
// From https://github.com/cypress-io/cypress/issues/2972#issuecomment-577072392
function getTestName() {
const cypressContext = Cypress.mocha.getRunner().suite.ctx.test;
const testTitles = [];
function extractTitles(obj) {
if (Object.hasOwn(obj, 'parent')) {
testTitles.push(obj.title);
const nextObj = obj.parent;
extractTitles(nextObj);
}
}
extractTitles(cypressContext);
const orderedTitles = testTitles.reverse();
const fileName = orderedTitles.join(' -- ');
return fileName;
}