From 39fc62904abfae6214b3498ee3b8634068ee8ab4 Mon Sep 17 00:00:00 2001 From: hkobew Date: Wed, 13 Nov 2024 15:17:08 -0500 Subject: [PATCH 1/2] add automatic retries to mocha setup --- packages/core/src/test/testRunner.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/test/testRunner.ts b/packages/core/src/test/testRunner.ts index ecac03475b..b53b555564 100644 --- a/packages/core/src/test/testRunner.ts +++ b/packages/core/src/test/testRunner.ts @@ -79,6 +79,7 @@ export async function runTests( mochaFile: outputFile, }, }, + retries: 3, // runs a max of 4 times (3 retries + original) timeout: 0, }) From f04e800121755d900b3da3cc6bde4a0096272124 Mon Sep 17 00:00:00 2001 From: hkobew Date: Wed, 13 Nov 2024 16:36:28 -0500 Subject: [PATCH 2/2] only add retries to unit tests --- packages/core/src/test/testRunner.ts | 10 +++++----- packages/toolkit/test/unit/index.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/core/src/test/testRunner.ts b/packages/core/src/test/testRunner.ts index b53b555564..9ba9c7cd01 100644 --- a/packages/core/src/test/testRunner.ts +++ b/packages/core/src/test/testRunner.ts @@ -22,7 +22,7 @@ export async function runTests( testFolder: string | string[], extensionId: string, initTests: string[] = [], - testFiles?: string[] + options?: { retries?: number; testFiles?: string[] } ): Promise { if (!process.env['AWS_TOOLKIT_AUTOMATION']) { throw new Error('Expected the "AWS_TOOLKIT_AUTOMATION" environment variable to be set for tests.') @@ -79,7 +79,7 @@ export async function runTests( mochaFile: outputFile, }, }, - retries: 3, // runs a max of 4 times (3 retries + original) + retries: options?.retries ?? 0, timeout: 0, }) @@ -92,7 +92,7 @@ export async function runTests( testFilePath = testFile ? path.resolve(dist, testFile) : undefined } - if (testFile && testFiles) { + if (testFile && options?.testFiles) { throw new Error('Individual file and list of files given to run tests on. One must be chosen.') } @@ -144,8 +144,8 @@ export async function runTests( } let files: string[] = [] - if (testFiles) { - files = testFiles + if (options?.testFiles) { + files = options.testFiles } else { for (const f of Array.isArray(testFolder) ? testFolder : [testFolder]) { files = [...files, ...(await glob(testFilePath ?? `**/${f}/**/**.test.js`, { cwd: dist }))] diff --git a/packages/toolkit/test/unit/index.ts b/packages/toolkit/test/unit/index.ts index 998953c7fd..6f2052d564 100644 --- a/packages/toolkit/test/unit/index.ts +++ b/packages/toolkit/test/unit/index.ts @@ -7,7 +7,10 @@ import { runTests } from 'aws-core-vscode/test' import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils' export function run(): Promise { - return runTests(process.env.TEST_DIR ?? ['test/unit', '../../core/dist/src/test'], VSCODE_EXTENSION_ID.awstoolkit, [ - '../../core/dist/src/test/globalSetup.test.ts', - ]) + return runTests( + process.env.TEST_DIR ?? ['test/unit', '../../core/dist/src/test'], + VSCODE_EXTENSION_ID.awstoolkit, + ['../../core/dist/src/test/globalSetup.test.ts'], + { retries: 3 } + ) }