-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run.sh script in FCS is not properly compatible with Mac (#149)
* 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
1 parent
f4f1d05
commit 5090ead
Showing
3 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters