From eae37d99e99ffbc72e1530fd23da368c22ba15ee Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:13:54 +0200 Subject: [PATCH] ci: fix empty retries env var (#11151) --- .github/workflows/deflake.yml | 1 + tools/mocha-runner/src/interface.ts | 12 ++++++------ tools/mocha-runner/src/utils.ts | 25 +++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deflake.yml b/.github/workflows/deflake.yml index 8b2a6871..521744e0 100644 --- a/.github/workflows/deflake.yml +++ b/.github/workflows/deflake.yml @@ -37,6 +37,7 @@ on: retries: description: Number of retries per test required: false + default: 100 type: number jobs: diff --git a/tools/mocha-runner/src/interface.ts b/tools/mocha-runner/src/interface.ts index 35eedab4..476c5138 100644 --- a/tools/mocha-runner/src/interface.ts +++ b/tools/mocha-runner/src/interface.ts @@ -32,7 +32,11 @@ const skippedTests: Array<{testIdPattern: string; skip: true}> = process.env[ ? JSON.parse(process.env['PUPPETEER_SKIPPED_TEST_CONFIG']) : []; -const deflakeRetries = Number(process.env['PUPPETEER_DEFLAKE_RETRIES'] ?? 100); +const deflakeRetries = Number( + process.env['PUPPETEER_DEFLAKE_RETRIES'] + ? process.env['PUPPETEER_DEFLAKE_RETRIES'] + : 100 +); const deflakeTestPattern: string | undefined = process.env['PUPPETEER_DEFLAKE_TESTS']; @@ -136,10 +140,7 @@ function customBDDInterface(suite: Mocha.Suite) { ); if (shouldDeflakeTest(test)) { const deflakeSuit = Mocha.Suite.create(suite, 'with Debug Logs'); - test.parent = deflakeSuit; - deflakeSuit.file = file; - deflakeSuit.parent = suite; - + test.file = file; deflakeSuit.beforeEach(function () { setLogCapture(true); }); @@ -147,7 +148,6 @@ function customBDDInterface(suite: Mocha.Suite) { for (let i = 0; i < deflakeRetries; i++) { deflakeSuit.addTest(test.clone()); } - return test; } else if (!(itOnly || describeOnly) && shouldSkipTest(test)) { const test = new Mocha.Test(title); diff --git a/tools/mocha-runner/src/utils.ts b/tools/mocha-runner/src/utils.ts index 4b8893ee..f78e0214 100644 --- a/tools/mocha-runner/src/utils.ts +++ b/tools/mocha-runner/src/utils.ts @@ -25,7 +25,7 @@ import type { } from './types.js'; export function extendProcessEnv(envs: object[]): NodeJS.ProcessEnv { - return envs.reduce( + const env = envs.reduce( (acc: object, item: object) => { Object.assign(acc, item); return acc; @@ -33,7 +33,28 @@ export function extendProcessEnv(envs: object[]): NodeJS.ProcessEnv { { ...process.env, } - ) as NodeJS.ProcessEnv; + ); + + if (process.env['CI']) { + const puppeteerEnv = Object.entries(env).reduce( + (acc, [key, value]) => { + if (key.startsWith('PUPPETEER_')) { + acc[key] = value; + } + + return acc; + }, + {} as Record + ); + + console.log( + 'PUPPETEER env:\n', + JSON.stringify(puppeteerEnv, null, 2), + '\n' + ); + } + + return env as NodeJS.ProcessEnv; } export function getFilename(file: string): string {