Skip to content

Commit

Permalink
ci: fix empty retries env var (#11151)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Oct 13, 2023
1 parent 8290dc9 commit eae37d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deflake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ on:
retries:
description: Number of retries per test
required: false
default: 100
type: number

jobs:
Expand Down
12 changes: 6 additions & 6 deletions tools/mocha-runner/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -136,18 +140,14 @@ 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);
});
deflakeSuit.afterEach(dumpLogsIfFail);
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);
Expand Down
25 changes: 23 additions & 2 deletions tools/mocha-runner/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,36 @@ 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;
},
{
...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<string, unknown>
);

console.log(
'PUPPETEER env:\n',
JSON.stringify(puppeteerEnv, null, 2),
'\n'
);
}

return env as NodeJS.ProcessEnv;
}

export function getFilename(file: string): string {
Expand Down

0 comments on commit eae37d9

Please sign in to comment.