Skip to content

Commit

Permalink
Add comprehensive testing based on features during CI
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki committed Jan 9, 2025
1 parent b7de273 commit 67e18e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion cypress/scripts/dynamic_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ const CONNECTION_RETRY_INTERVAL = 15000;
const checkSecurity = async (config: Cypress.PluginConfigOptions) => {
const startTime = Date.now();
do {
const apiStatusUrl = new URL('/api/status', config.baseUrl);
// Not catching to allow Cypress to fail
const resp = await fetch(config.baseUrl, { timeout: CONNECTION_TIMEOUT });
const resp = await fetch(apiStatusUrl, { timeout: CONNECTION_TIMEOUT });

if (resp.status === 200) {
console.log('OpenSearch Dashboards is configured without security.');
Expand Down Expand Up @@ -80,6 +81,8 @@ const checkPlugins = async (config: Cypress.PluginConfigOptions) => {
.replace(/([A-Z])/g, '_$1')
.toUpperCase();
config.env[`${envName}_ENABLED`] = true;

console.log(`${envName} is enabled.`);
});

return;
Expand Down
21 changes: 13 additions & 8 deletions cypress/support/conditional_describers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,31 @@
/**
* Helper function to describe conditional test suites, based on features enabled in OSD
*
* @param {string} featureName - The name of feature to be checked.
* @param {string[] | string} featureNames - The name of feature to be checked.
* Based on the status of the feature, the suite will be described.
*
* @returns {Mocha.SuiteFunction & { describe: Mocha.SuiteFunction, not: Mocha.SuiteFunction & { describe: Mocha.SuiteFunction }}}
*/

const ifEnabled = (featureName) => {
const ifEnabled = (featureNames) => {
/**
* Describes a "suite" that should be executed if the feature is enabled.
* @type {Mocha.SuiteFunction & { not: Mocha.SuiteFunction & {describe: Mocha.SuiteFunction}}}
*/
const describer = (name, fn, options = {}) => {
const { skip = false, only = false, condition = true, not = false } = options;

if (
skip ||
!condition ||
(!not && !Cypress.env(`${featureName}_ENABLED`)) ||
(not && Cypress.env(`${featureName}_ENABLED`))
) {
let shouldSkip = skip || !condition;
if (!shouldSkip) {
const allFeaturesAreEnabled = (Array.isArray(featureNames)
? featureNames
: [featureNames]
).every((name) => Cypress.env(`${name}_ENABLED`));

shouldSkip = not ? !allFeaturesAreEnabled : allFeaturesAreEnabled;
}

if (shouldSkip) {
describe.skip(name, fn);
} else if (only) {
// eslint-disable-next-line mocha/no-exclusive-tests
Expand Down

0 comments on commit 67e18e8

Please sign in to comment.