## 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
163 lines
4.9 KiB
JavaScript
163 lines
4.9 KiB
JavaScript
/// <reference types="cypress" />
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const dotenv = require("dotenv");
|
|
const chalk = require("chalk");
|
|
// const _ = require("lodash");
|
|
// const del = require("del");
|
|
const cypressLogToOutput = require("cypress-log-to-output");
|
|
//const { isFileExist } = require("cy-verify-downloads");
|
|
const {
|
|
addMatchImageSnapshotPlugin,
|
|
} = require("cypress-image-snapshot/plugin");
|
|
const { tagify } = require("cypress-tags");
|
|
// ***********************************************************
|
|
// 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)
|
|
|
|
/**
|
|
* @type {Cypress.PluginConfig}
|
|
*/
|
|
module.exports = (on, config) => {
|
|
// Todo: maybe raise a PR instead of overwriting `on("before:browser:launch", ...)` twice.
|
|
cypressLogToOutput.install(on, (type, event) => {
|
|
if (event.level === "error" || event.type === "error") {
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
};
|
|
|
|
// module.exports = (on, config) => {
|
|
// on("after:spec", (spec, results) => {
|
|
// if (results && results.video) {
|
|
// // Do we have failures for any retry attempts?
|
|
// const failures = _.some(results.tests, (test) => {
|
|
// return _.some(test.attempts, { state: "failed" });
|
|
// });
|
|
// if (!failures) {
|
|
// // delete the video if the spec passed and no tests retried
|
|
// return del(results.video);
|
|
// }
|
|
// }
|
|
// });
|
|
// };
|
|
|
|
module.exports = (on, config) => {
|
|
// on("task", {
|
|
// isFileExist,
|
|
// });
|
|
// `on` is used to hook into various events Cypress emits
|
|
// `config` is the resolved Cypress config
|
|
on("before:browser:launch", (browser = {}, launchOptions) => {
|
|
/*
|
|
Uncomment below to get console log printed in cypress output
|
|
*/
|
|
|
|
launchOptions.args = cypressLogToOutput.browserLaunchHandler(
|
|
browser,
|
|
launchOptions.args,
|
|
);
|
|
if (browser.name === "chrome") {
|
|
launchOptions.args.push("--disable-dev-shm-usage");
|
|
launchOptions.push("--window-size=1400,1100");
|
|
return launchOptions;
|
|
}
|
|
|
|
if (browser.name === "electron") {
|
|
// && browser.isHeadless) {
|
|
launchOptions.preferences.fullscreen = true;
|
|
launchOptions.preferences.darkTheme = true;
|
|
launchOptions["width"] = 1400;
|
|
launchOptions["height"] = 1100;
|
|
launchOptions["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;
|
|
},
|
|
});
|
|
|
|
return config;
|
|
};
|
|
|
|
module.exports = (on, config) => {
|
|
on("file:preprocessor", tagify(config));
|
|
addMatchImageSnapshotPlugin(on, config);
|
|
};
|