Skip to content

Commit 0ee1130

Browse files
authored
feat: validate other parameters against command parameter when used (#1445)
* feat: validate other parameters against command parameter when used * add env and change quotes
1 parent 83ed16e commit 0ee1130

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

dist/index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93982,10 +93982,58 @@ const runTestsUsingCommandLine = async () => {
9398293982

9398393983
return exec.exec(quote(npxPath), cmd, opts)
9398493984
}
93985+
/**
93986+
* Validate input parameters for consistency when command parameter is used
93987+
* Output GitHub actions annotation warning if ignored parameters are used
93988+
*/
93989+
const commandIgnoredBooleanInputs = [
93990+
// parameter name, default value
93991+
['component', false],
93992+
['headed', false],
93993+
['parallel', false],
93994+
['quiet', false],
93995+
['record', false],
93996+
['publish-summary', true]
93997+
]
93998+
const commandIgnoredStringInputs = [
93999+
'auto-cancel-after-failures',
94000+
'browser',
94001+
'ci-build-id',
94002+
'config',
94003+
'config-file',
94004+
'env',
94005+
'group',
94006+
'project',
94007+
'spec',
94008+
'tag',
94009+
'command-prefix',
94010+
'summary-title'
94011+
]
94012+
let ignoredInputParameters = []
94013+
const validateCustomCommand = () => {
94014+
commandIgnoredBooleanInputs.forEach((input) => {
94015+
const inputParameter = input[0]
94016+
const inputDefault = input[1]
94017+
if (getInputBool(inputParameter) !== inputDefault) {
94018+
ignoredInputParameters.push(inputParameter)
94019+
}
94020+
})
94021+
commandIgnoredStringInputs.forEach((input) => {
94022+
if (core.getInput(input)) {
94023+
ignoredInputParameters.push(input)
94024+
}
94025+
})
94026+
if (ignoredInputParameters.length > 0) {
94027+
core.warning(
94028+
`command parameter is used and the following other parameters are ignored: ${ignoredInputParameters.sort().join(', ')}.`
94029+
)
94030+
}
94031+
}
9398594032

9398694033
/**
9398794034
* Run Cypress tests by collecting input parameters
9398894035
* and using Cypress module API to run tests.
94036+
* If command parameter is specified, then run using @actions/exec instead.
9398994037
* @see https://on.cypress.io/module-api
9399094038
*/
9399194039
const runTests = async () => {
@@ -94014,6 +94062,7 @@ const runTests = async () => {
9401494062

9401594063
if (customCommand) {
9401694064
console.log('Using custom test command: %s', customCommand)
94065+
validateCustomCommand() // catch ignored parameters and output warning
9401794066
return execCommand(customCommand, true, 'run tests')
9401894067
}
9401994068

index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,58 @@ const runTestsUsingCommandLine = async () => {
719719

720720
return exec.exec(quote(npxPath), cmd, opts)
721721
}
722+
/**
723+
* Validate input parameters for consistency when command parameter is used
724+
* Output GitHub actions annotation warning if ignored parameters are used
725+
*/
726+
const commandIgnoredBooleanInputs = [
727+
// parameter name, default value
728+
['component', false],
729+
['headed', false],
730+
['parallel', false],
731+
['quiet', false],
732+
['record', false],
733+
['publish-summary', true]
734+
]
735+
const commandIgnoredStringInputs = [
736+
'auto-cancel-after-failures',
737+
'browser',
738+
'ci-build-id',
739+
'config',
740+
'config-file',
741+
'env',
742+
'group',
743+
'project',
744+
'spec',
745+
'tag',
746+
'command-prefix',
747+
'summary-title'
748+
]
749+
let ignoredInputParameters = []
750+
const validateCustomCommand = () => {
751+
commandIgnoredBooleanInputs.forEach((input) => {
752+
const inputParameter = input[0]
753+
const inputDefault = input[1]
754+
if (getInputBool(inputParameter) !== inputDefault) {
755+
ignoredInputParameters.push(inputParameter)
756+
}
757+
})
758+
commandIgnoredStringInputs.forEach((input) => {
759+
if (core.getInput(input)) {
760+
ignoredInputParameters.push(input)
761+
}
762+
})
763+
if (ignoredInputParameters.length > 0) {
764+
core.warning(
765+
`command parameter is used and the following other parameters are ignored: ${ignoredInputParameters.sort().join(', ')}.`
766+
)
767+
}
768+
}
722769

723770
/**
724771
* Run Cypress tests by collecting input parameters
725772
* and using Cypress module API to run tests.
773+
* If command parameter is specified, then run using @actions/exec instead.
726774
* @see https://on.cypress.io/module-api
727775
*/
728776
const runTests = async () => {
@@ -751,6 +799,7 @@ const runTests = async () => {
751799

752800
if (customCommand) {
753801
console.log('Using custom test command: %s', customCommand)
802+
validateCustomCommand() // catch ignored parameters and output warning
754803
return execCommand(customCommand, true, 'run tests')
755804
}
756805

0 commit comments

Comments
 (0)