Skip to content

Commit

Permalink
run.sh script in FCS is not properly compatible with Mac (#149)
Browse files Browse the repository at this point in the history
* add run js

* add run js

* minor fix for open func

* Update NOTICE file for Open Source compliance

---------

Co-authored-by: Joe Meier <joseph_meier@comcast.com>
  • Loading branch information
bpvstaty366 and jmeier204 authored Jul 23, 2024
1 parent f4f1d05 commit 5090ead
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ Licensed under the MIT License

scenarios-original.tmpl is taken from https://github.com/WasiqB/multiple-cucumber-html-reporter which is:
Copyright (c) 2023 Wasiq Bhamla
Licensed under the MIT License

Scripts/run.js uses code provided by cross-spawn taken from https://github.com/moxystudio/node-cross-spawn
Copyright (c) 2018 Made With MOXY Lda hello@moxy.studio
Licensed under the MIT License
104 changes: 104 additions & 0 deletions Scripts/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const spawn = require('cross-spawn');
const { v4: uuidv4 } = require('uuid');

// Reading first parameter from the scripts to call function
const functionName = process.argv[2];
const params = process.argv.slice(3).join(' ');

// Creating UUID
function generateUUID() {
return uuidv4();
}

// Function to extract value of params that contain spaces
function modifyParams(params) {
const envSectionMatch = params.match(/--env\s+(.*?)(?=\s+--|$)/);
const envSection = envSectionMatch ? envSectionMatch[1] : '';
const paramValuePairs = envSection.split(',');

let modifiedParams = params;
for (const pair of paramValuePairs) {
if (pair.includes(' ')) {
const [key, value] = pair.split('=');
process.env[`CYPRESS_${key}`] = value;
modifiedParams = modifiedParams.replace(pair + ',', '').replace(',' + pair, '');
}
}
return modifiedParams;
}

// Function to check if it's a combined test run
function isCombinedTestRun(params) {
const specValueMatch = params.match(/--spec\s+([^ ]*)/);
const specValue = specValueMatch ? specValueMatch[1] : '';
return specValue === '*' || specValue.includes(',');
}

const isCombinedTest = isCombinedTestRun(params);
process.env.CYPRESS_isCombinedTestRun = isCombinedTest;

// Extract jobId from the parameters
let jobId = '';
const processingEnvArgs = params.includes('--env');
if (processingEnvArgs) {
const envArgs = params.match(/--env\s+(.*?)(?=\s+--|$)/)[1].split(',');
for (const envArg of envArgs) {
if (envArg.startsWith('jobId=')) {
jobId = envArg.split('=')[1];
break;
}
}
}

// If jobId is not found in the parameters, generate a new one
if (!jobId) {
jobId = generateUUID();
}

process.env.CYPRESS_jobId = jobId;

// Function to execute cypress run
function run() {
const args = ['run', '--e2e', ...modifyParams(params).split(' ')];
console.log(`[Running cypress command: cypress ${args.join(' ')}]`);

const cypressProcess = spawn('cypress', args, { stdio: 'inherit' });

cypressProcess.on('error', (error) => {
console.error(`Error: ${error.message}`);
});

cypressProcess.on('close', (code) => {
if (code !== 0) {
console.error(`Cypress process exited with code ${code}`);
}
});
}

// Function to open Cypress without report options
function open() {
const command = 'cypress';
const args = ['open', '--e2e', ...modifyParams(params).split(' ')];
console.log(`[Running cypress command: ${command} ${args.join(' ')}]`);

const cypressProcess = spawn(command, args, { stdio: 'inherit' });

cypressProcess.on('error', (error) => {
console.error(`Error: ${error.message}`);
});

cypressProcess.on('close', (code) => {
if (code !== 0) {
console.error(`Cypress process exited with code ${code}`);
}
});
}

// Calling function based on name
if (functionName === 'run') {
run();
} else if (functionName === 'open') {
open();
} else {
console.error('Invalid function name');
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Firebolt Certification Test Suite",
"main": "index.js",
"scripts": {
"cy:open": "node ./Scripts/checkDefaultConfig.js && yarn cache clean && sh ./Scripts/run.sh open",
"cy:run": "node ./Scripts/checkDefaultConfig.js && yarn cache clean && bash ./Scripts/run.sh run",
"cy:open": "node ./Scripts/checkDefaultConfig.js && yarn cache clean && node ./Scripts/run.js open",
"cy:run": "node ./Scripts/checkDefaultConfig.js && yarn cache clean && node ./Scripts/run.js run",
"softRefresh": "yarn install && yarn upgrade",
"hardRefresh": "rm -rf node_modules && yarn cache clean && yarn softRefresh",
"copyCukeReportTemplate": "node ./Scripts/copyCukeReportTemplate.js",
Expand All @@ -32,6 +32,7 @@
"axios": "^1.3.4",
"configModule": "./defaultModule",
"cucumber-json-report-formatter": "^0.1.4",
"cross-spawn": "^7.0.3",
"cypress": "^12.0.0",
"esbuild": "^0.17.0",
"flatted": "^3.3.1",
Expand Down Expand Up @@ -67,4 +68,4 @@
"enabled": true
}
}
}
}

0 comments on commit 5090ead

Please sign in to comment.