From 301852dcd727565ff74ebe5d3516dcc9a63f3d1b Mon Sep 17 00:00:00 2001 From: Saroj <43822041+sarojsarab@users.noreply.github.com> Date: Fri, 25 Aug 2023 15:06:05 +0530 Subject: [PATCH] test: Fix cypress local run (#26652) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description - Fix cypress local run #### PR fixes following issue(s) Fixes # (issue number) > if no issue exists, please create an issue and ask the maintainers about this first > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- .github/workflows/upgrade-appsmith-tests.yml | 3 +-- app/client/cypress/scripts/cypress-hooks.js | 26 +++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/upgrade-appsmith-tests.yml b/.github/workflows/upgrade-appsmith-tests.yml index 38c19c0d55..e0628ea5f2 100644 --- a/.github/workflows/upgrade-appsmith-tests.yml +++ b/.github/workflows/upgrade-appsmith-tests.yml @@ -121,5 +121,4 @@ jobs: - name: Check ci-test set status if: needs.ci-test.result != 'success' - run: exit 1 - \ No newline at end of file + run: exit 1 \ No newline at end of file diff --git a/app/client/cypress/scripts/cypress-hooks.js b/app/client/cypress/scripts/cypress-hooks.js index 991a89a6ba..117c548cb2 100644 --- a/app/client/cypress/scripts/cypress-hooks.js +++ b/app/client/cypress/scripts/cypress-hooks.js @@ -36,16 +36,19 @@ function configureDbClient() { } // This is to setup the AWS client -AWS.config.update({ region: "ap-south-1" }); -const s3 = new AWS.S3({ - credentials: { - accessKeyId: getEnvValue("CYPRESS_S3_ACCESS", { required: true }), - secretAccessKey: getEnvValue("CYPRESS_S3_SECRET", { required: true }), - }, -}); +function configureS3() { + AWS.config.update({ region: "ap-south-1" }); + const s3client = new AWS.S3({ + credentials: { + accessKeyId: getEnvValue("CYPRESS_S3_ACCESS", { required: true }), + secretAccessKey: getEnvValue("CYPRESS_S3_SECRET", { required: true }), + }, + }); + return s3client; +} // This is to upload files to s3 when required -function uploadToS3(filePath, key) { +function uploadToS3(s3Client, filePath, key) { const fileContent = fs.readFileSync(filePath); const params = { @@ -53,10 +56,11 @@ function uploadToS3(filePath, key) { Key: key, Body: fileContent, }; - return s3.upload(params).promise(); + return s3Client.upload(params).promise(); } async function cypressHooks(on, config) { + const s3 = configureS3(); const dbClient = configureDbClient(); const runData = { commitMsg: getEnvValue("COMMIT_INFO_MESSAGE", { required: false }), @@ -182,7 +186,7 @@ async function cypressHooks(on, config) { const key = `${testResponse.rows[0].id}_${specData.specId}_${ scr.testAttemptIndex + 1 }`; - Promise.all([uploadToS3(scr.path, key)]).catch((error) => { + Promise.all([uploadToS3(s3, scr.path, key)]).catch((error) => { console.log("Error in uploading screenshots:", error); }); } @@ -197,7 +201,7 @@ async function cypressHooks(on, config) { ) { console.log("Uploading video..."); const key = `${specData.specId}`; - Promise.all([uploadToS3(results.video, key)]).catch((error) => { + Promise.all([uploadToS3(s3, results.video, key)]).catch((error) => { console.log("Error in uploading video:", error); }); }