Skip to content

Commit

Permalink
[ci/screenshots] enable discovering truncated screenshot names (#133950)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored Jun 8, 2022
1 parent bc591ae commit 42ba236
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 8 additions & 5 deletions test/functional/services/common/failure_debugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)]);
}
Expand Down

0 comments on commit 42ba236

Please sign in to comment.