[ci/screenshots] enable discovering truncated screenshot names (#133950) (#133967)

(cherry picked from commit 42ba236b8e)

Co-authored-by: Spencer <spencer@elastic.co>
This commit is contained in:
Kibana Machine 2022-06-08 19:05:43 -04:00 committed by GitHub
parent 90dcf78dd5
commit 768254c71c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -96,7 +96,10 @@ export function reportFailuresToFile(
);
let screenshot = '';
const screenshotName = `${failure.name.replace(/([^ a-zA-Z0-9-]+)/g, '_')}`;
const truncatedName = failure.name.replace(/([^ a-zA-Z0-9-]+)/g, '_').slice(0, 80);
const failureNameHash = createHash('sha256').update(failure.name).digest('hex');
const screenshotName = `${truncatedName}-${failureNameHash}`;
if (screenshotsByName[screenshotName]) {
try {
screenshot = readFileSync(screenshotsByName[screenshotName]).toString('base64');

View file

@ -9,7 +9,7 @@
import { resolve } from 'path';
import { writeFile, mkdir } from 'fs';
import { promisify } from 'util';
import Uuid from 'uuid';
import { createHash } from 'crypto';
import del from 'del';
import { FtrProviderContext } from '../../ftr_provider_context';
@ -49,11 +49,14 @@ export async function FailureDebuggingProvider({ getService }: FtrProviderContex
}
async function onFailure(_: any, test: Test) {
const fullName = test.fullTitle();
// include a hash of the full title of the test in the filename so that even with truncation filenames are
// always unique and deterministic based on the test title
const hash = createHash('sha256').update(fullName).digest('hex');
// Replace characters in test names which can't be used in filenames, like *
let name = test.fullTitle().replace(/([^ a-zA-Z0-9-]+)/g, '_');
if (name.length > 100) {
name = `truncated-${name.slice(-100)}-${Uuid.v4()}`;
}
const name = `${fullName.replace(/([^ a-zA-Z0-9-]+)/g, '_').slice(0, 80)}-${hash}`;
await Promise.all([screenshots.takeForFailure(name), logCurrentUrl(), savePageHtml(name)]);
}