PromucFlow_constructor/app/client/cypress/plugins/index.js

224 lines
6.5 KiB
JavaScript
Raw Normal View History

2020-03-10 09:38:12 +00:00
/// <reference types="cypress" />
const fs = require("fs");
const path = require("path");
const dotenv = require("dotenv");
const chalk = require("chalk");
const cypressLogToOutput = require("cypress-log-to-output");
const installLogsPrinter = require("cypress-terminal-report/src/installLogsPrinter");
feat: ci changes & cypress tests with cypress tags (#22989) ## Description This includes > Building a new image for airgapped instances > Running ci-tests on airgapped image > Running cypress tests selectively ignoring non supported features for airgap like Templates, Custom JS lib and also alternating test behaviours for some tests like tests using mock db, since it doesn't work on airgap we have to create a ds. So this selective testing was done using cypress-tags > Having a new client build for airgapped images which bundles all the assets. > And changes in the workflow files to account for all the above. With airgap, we can ignore certain tests and also need to account for tests using mock datasources and such by creating new datasources instead of mock datasources. Since those are blocked. So to perform a selective testing we are using a plugin called `cypress-tags` and to perform conditional testing when required we use the `AIRGAPPED` cypress env. This PR introduces both and also modified the codebase to support this new way of running cypress. Since we can't trigger `/ok-to-test` on this because ci-test needs the CYPRESS_EXCLUDE_TAGS and slash command doesn't dispatch from current branch, I manually triggered the `TBP` workflow to run ci-test on this branch. And the new `TBP airgap` workflow to run ci-test on airgapped docker image on this branch. Here is the link to the run https://github.com/appsmithorg/appsmith/actions/runs/4882041416 Fixes #22007 Fixes #22814 ## Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? - Manual - 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 - [x] My code follows the style guidelines of this project - [x] 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 - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-05-11 18:45:06 +00:00
const { tagify } = require("cypress-tags");
chore: Changes to enable internal cypress dashboard (#26626) > Pull Request Template > > Use this template to quickly create a well written pull request. Delete all quotes before creating the pull request. > ## Description > Add a TL;DR when description is extra long (helps content team) > > Please include a summary of the changes and which issue has been fixed. Please also include relevant motivation > and context. List any dependencies that are required for this change > > Links to Notion, Figma or any other documents that might be relevant to the PR > > #### 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
2023-08-25 04:51:12 +00:00
const { cypressHooks } = require("../scripts/cypress-hooks");
const { dynamicSplit } = require("../scripts/cypress-split-dynamic");
const { staticSplit } = require("../scripts/cypress-split-static");
2019-12-12 07:50:53 +00:00
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
2020-03-10 09:38:12 +00:00
/**
* @type {Cypress.PluginConfig}
*/
module.exports = async (on, config) => {
cypressLogToOutput.install(on, (type, event) => {
if (event.level === "error" || event.type === "error") {
return true;
}
return false;
});
const logsPrinterOptions = {
outputRoot: config.projectRoot + "/cypress/",
outputTarget: {
"cypress-logs|json": "json",
},
specRoot: "cypress/e2e",
printLogsToFile: "onFail",
};
installLogsPrinter(on, logsPrinterOptions);
on("file:preprocessor", tagify(config));
on("before:browser:launch", (browser = {}, launchOptions) => {
/*
Uncomment below to get console log printed in cypress output
*/
launchOptions.args = cypressLogToOutput.browserLaunchHandler(
browser,
launchOptions.args,
);
chore: change snapshot package (#35867) /ok-to-test tags="@tag.All" ## Description > [!TIP] > _Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team)._ > > _Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR._ Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10815637874> > Commit: 54937a7a64e755959e3420a0a20abcc30ee10d78 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10815637874&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Wed, 11 Sep 2024 17:30:00 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for visual regression testing through new tagging in various test suites. - Integrated a new image snapshot plugin to enhance testing capabilities. - **Bug Fixes** - Removed outdated image snapshot assertions to streamline testing processes. - **Documentation** - Updated tags in multiple test suites to improve organization and clarity regarding visual testing. - **Chores** - Upgraded Node.js version in the Cypress Dockerfile for improved performance and compatibility. - Simplified Cypress plugin configuration by removing unnecessary functions and enhancing browser compatibility. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro-2.local>
2024-09-12 08:09:42 +00:00
if (browser.name === "chrome" || browser.name === "chromium") {
const video = path.join(
"cypress",
"fixtures",
"Videos",
"webCamVideo.y4m",
);
launchOptions.args.push("--disable-dev-shm-usage");
launchOptions.args.push("--window-size=1400,1100");
launchOptions.args.push("--use-fake-ui-for-media-stream");
launchOptions.args.push("--use-fake-device-for-media-stream");
//Stream default video source for camera & code scanner
launchOptions.args.push(`--use-file-for-fake-video-capture=${video}`);
return launchOptions;
}
if (browser.name === "electron") {
// && browser.isHeadless) {
launchOptions.preferences.fullscreen = true;
launchOptions.preferences.darkTheme = true;
launchOptions.preferences.width = 1400;
launchOptions.preferences.height = 1100;
launchOptions.preferences.resizable = false;
return launchOptions;
}
});
/**
* Fallback to APPSMITH_* env variables for Cypress.env if config.env doesn't already have it.
* Note: APPSMITH_* ENV vars have lower precedence than *all* methods mentioned in https://docs.cypress.io/guides/guides/environment-variables.html
* Example #1:
* process.env -> APPSMITH_FOO=bar
* cypress.json -> APPSMITH_FOO=baz
*
* Cypress.env("APPSMITH_FOO") // baz
*
* Example #2:
* process.env -> APPSMITH_FOO=bar
* cypress.json -> APPSMITH_FOO=
*
* Cypress.env("APPSMITH_FOO") // <empty>
*/
Object.keys(process.env).forEach((key) => {
if (
key.startsWith("APPSMITH_") &&
!Object.prototype.hasOwnProperty.call(config.env, key)
) {
config.env[key] = process.env[key];
}
});
/**
* Fallback to .env variables for Cypress.env if procecss.env doesn't have it either
* Note: Value in .env file has the lowest precedence, even lower than APPSMITH_* ENV vars.
* Example:
* .env -> APPSMITH_FOO=bar
* process.env -> APPSMITH_FOO=
*
* Cypress.env("APPSMITH_FOO") // <empty>
*/
try {
const parsedEnv = dotenv.parse(
fs.readFileSync(path.join(__dirname, "../../../../.env"), {
encoding: "utf-8",
}),
);
Object.keys(parsedEnv).forEach((key) => {
if (!Object.prototype.hasOwnProperty.call(config.env, key)) {
config.env[key] = parsedEnv[key];
}
});
} catch (e) {
console.error(
chalk.yellow(
"\n====================================================================================================\n" +
chalk.red(e.message) +
"\n\n" +
"Could not load env variables from .env file, make sure you have one!\n" +
"====================================================================================================\n",
),
);
}
/**
* This task logs the message on the CLI terminal. Use with care because it can log sensitive details
* Example usage: cy.task('log', 'This is the message printed to the terminal')
*/
on("task", {
log(message) {
console.log(message);
return null;
},
/*
chore: cypress snapshot types (#34722) ## Description 1. Add scripts for local e2e testing in the docker container. 2. Add types for cypress-image-snapshot In this PR, I also added the following PRS as they affect screenshot tests as well. I did this to speed up the process and unblock the team. #34528 #34546 #34676 #34729 #34638 #34639 #34511 To run E2E tests locally in docker, you need to do the following: 1. Run FE locally and prepare the tests for local launch. See the instructions [here](https://github.com/appsmithorg/appsmith/blob/release/contributions/ClientSetup.md). 2. Run `yarn cypress:snapshot:docker:build` — this will create a docker container with the necessary environment. 3. Run `yarn cypress:snapshot:docker "./cypress/e2e/Regression/ClientSide/Anvil/Widgets/*_spec.ts" updateSnapshots=false`. Here we can use the path to a specific file, or set `updateSnapshots=true` flag to update the screenshots. ## Automation /ok-to-test tags="@tag.Anvil" ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9844579277> > Commit: 75f26599b149f831051fbd631aaa059084b226dd > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9844579277&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Anvil` > Spec: > <hr>Mon, 08 Jul 2024 18:37:36 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for image snapshot testing with the `@types/cypress-image-snapshot` dependency. - **Refactor** - Updated test specifications by removing unnecessary `triggerInputInvalidState()` calls. - Reorganized and improved efficiency of image snapshot methods for various devices. - **Chores** - Updated `Dockerfile` to configure the Cypress environment with specific versions for dependencies. - Changed import paths in `e2e.js` for better module resolution. - **Style** - Fixed a comment typo in Cypress plugin configuration. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro-2.local> Co-authored-by: unknown <vadim@appsmith.com>
2024-07-09 09:06:59 +00:00
Change video source for for camera & code scanner
*/
changeVideoSource(videoSource) {
console.log("TASK - Changing video source to", videoSource);
const webcamPath = path.join(
"cypress",
"fixtures",
"Videos",
"webCamVideo.y4m",
);
const defaultVideoPath = path.join(
"cypress",
"fixtures",
"Videos",
videoSource,
);
const video = fs.readFileSync(defaultVideoPath);
fs.writeFile(webcamPath, video);
return null;
},
/*
Reset video source to default
*/
resetVideoSource() {
console.log("TASK - Resetting video source");
const webcamPath = path.join(
"cypress",
"fixtures",
"Videos",
"webCamVideo.y4m",
);
const defaultVideoPath = path.join(
"cypress",
"fixtures",
"Videos",
"defaultVideo.y4m",
);
const video = fs.readFileSync(defaultVideoPath);
fs.writeFile(webcamPath, video);
return null;
},
});
test: Cypress - Added cypress grep library (#29259) Leveraging the library [cypress-grep](https://github.com/cypress-io/cypress/tree/develop/npm/grep). Using this we can tag testcases with relevant tags and use it to run specific testcases. **Command to run in local:** `CYPRESS_grepTags=@tag.Binding,@tag.Git npx cypress run ` Pass the tags to CYPRESS_grepTags argument and only the test cases which has the tags passed will be picked to run. ex `@tag.Binding and @tag.Git` are the tag names here. **Tags can be added in the description on the test case like** `{ tags: ["@tag.Datasource"] }` for a single tag `{ tags: ["@tag.Datasource", "@tag.Git"] }` for multiple tags **How to run In CI** Single Tag - `/ok-to-test tags=@tag.Binding` Multiple tag - `/ok-to-test tags=@tag.Binding,@tag.Git` **TODOs in the next release:** - [ ] Add tags.ts file with all needed tags - [ ] Add tags to remaining spec files. - [ ] Fail the PR run if tags added are not from tag.ts and post the message on the same #### Type of change - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update #### How Has This Been Tested? - [x] Manual - [ ] JUnit - [ ] Jest - [x] Cypress ## 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 - [x] My changes generate no new warnings - [x] 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: - [x] [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 - [x] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a search functionality to the app. - **Enhancements** - Integrated search bar at the top of the `Hero` component and a `Search` component to the `App` component. - Added styles for the search bar. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2023-12-07 12:53:27 +00:00
console.log("Type of 'config.specPattern':", typeof config.specPattern);
/**
* Cypress grep plug return specPattern as object and with absolute path
*/
if (typeof config.specPattern == "object") {
config.specPattern = config.specPattern.map((spec) => {
return spec.replace(process.cwd() + "/", "");
});
}
console.log("config.specPattern:", config.specPattern);
if (process.env["RUNID"]) {
config =
process.env["CYPRESS_STATIC_ALLOCATION"] == "true"
? await new staticSplit().splitSpecs(config)
: await new dynamicSplit().splitSpecs(config);
cypressHooks(on, config);
}
return config;
};