From f5943cd8a7ae161fbec5be57e76aa8fc37a69e76 Mon Sep 17 00:00:00 2001 From: Eric Leese Date: Wed, 30 Aug 2023 13:16:33 +0200 Subject: [PATCH] Log cas-viewer url to screenshot html file Code predicts the cas-viewer url where the screenshots file will be uploaded so that the link can be copied from the test log. Bug: None Change-Id: Ia5739f7915c2ab657ab8085ce20496327f552684 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4813643 Commit-Queue: Eric Leese Reviewed-by: Almothana Athamneh --- test/conductor/mocha_hooks.ts | 14 ++++++++++++++ test/shared/mocha-extensions.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/conductor/mocha_hooks.ts b/test/conductor/mocha_hooks.ts index 1c2939ab96..9b5068cea0 100644 --- a/test/conductor/mocha_hooks.ts +++ b/test/conductor/mocha_hooks.ts @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import * as Crypto from 'crypto'; import * as fs from 'fs'; import {createCoverageMap, createFileCoverage} from 'istanbul-lib-coverage'; import * as report from 'istanbul-lib-report'; @@ -62,6 +63,18 @@ export function mochaGlobalTeardown() { stopServer(); } +function logScreenshotFileUrl() { + const screenshotFile = process.env.HTML_OUTPUT_FILE; + if (screenshotFile) { + const hash = Crypto.createHash('sha256'); + const contents = fs.readFileSync(screenshotFile); + hash.update(contents); + console.error( + `If running on bots, screenshots can be downloaded from: https://cas-viewer.appspot.com/projects/chromium-swarm/instances/default_instance/blobs/${ + hash.digest('hex')}/${contents.byteLength}?filename=screenshots.html`); + } +} + const testSuiteCoverageMap = createCoverageMap(); const testsRunWithCoverageEnvSet = Boolean(process.env.COVERAGE || process.env.COVERAGE_FOLDERS); @@ -88,6 +101,7 @@ export const mochaHooks = { // In parallel mode, run after all tests end, for each file. afterAll: async function(this: Mocha.Suite) { await postFileTeardown(); + logScreenshotFileUrl(); if (!SHOULD_GATHER_COVERAGE_INFORMATION) { return; diff --git a/test/shared/mocha-extensions.ts b/test/shared/mocha-extensions.ts index bc729ef3f4..f2b6cb6a42 100644 --- a/test/shared/mocha-extensions.ts +++ b/test/shared/mocha-extensions.ts @@ -12,7 +12,7 @@ import {AsyncScope} from './async-scope.js'; import {getEnvVar} from './config.js'; import {platform, type Platform, stepDescription} from './helper.js'; -export {beforeEach} from 'mocha'; +export {after, beforeEach} from 'mocha'; let didInitializeHtmlOutputFile = false;