Skip to content

Commit ae88a0b

Browse files
committed
feat: validate other parameters against command parameter when used
1 parent 6f72d0f commit ae88a0b

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

dist/index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93982,10 +93982,57 @@ 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+
`group`,
94005+
`project`,
94006+
`spec`,
94007+
`tag`,
94008+
`command-prefix`,
94009+
`summary-title`
94010+
]
94011+
let ignoredInputParameters = []
94012+
const validateCustomCommand = () => {
94013+
commandIgnoredBooleanInputs.forEach((input) => {
94014+
const inputParameter = input[0]
94015+
const inputDefault = input[1]
94016+
if (getInputBool(inputParameter) !== inputDefault) {
94017+
ignoredInputParameters.push(inputParameter)
94018+
}
94019+
})
94020+
commandIgnoredStringInputs.forEach((input) => {
94021+
if (core.getInput(input)) {
94022+
ignoredInputParameters.push(input)
94023+
}
94024+
})
94025+
if (ignoredInputParameters.length > 0) {
94026+
core.warning(
94027+
`command parameter is used and the following other parameters are ignored: ${ignoredInputParameters.sort().join(', ')}.`
94028+
)
94029+
}
94030+
}
9398594031

9398694032
/**
9398794033
* Run Cypress tests by collecting input parameters
9398894034
* and using Cypress module API to run tests.
94035+
* If command parameter is specified, then run using @actions/exec instead.
9398994036
* @see https://on.cypress.io/module-api
9399094037
*/
9399194038
const runTests = async () => {
@@ -94014,6 +94061,7 @@ const runTests = async () => {
9401494061

9401594062
if (customCommand) {
9401694063
console.log('Using custom test command: %s', customCommand)
94064+
validateCustomCommand() // catch ignored parameters and output warning
9401794065
return execCommand(customCommand, true, 'run tests')
9401894066
}
9401994067

index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,10 +719,57 @@ 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+
`group`,
742+
`project`,
743+
`spec`,
744+
`tag`,
745+
`command-prefix`,
746+
`summary-title`
747+
]
748+
let ignoredInputParameters = []
749+
const validateCustomCommand = () => {
750+
commandIgnoredBooleanInputs.forEach((input) => {
751+
const inputParameter = input[0]
752+
const inputDefault = input[1]
753+
if (getInputBool(inputParameter) !== inputDefault) {
754+
ignoredInputParameters.push(inputParameter)
755+
}
756+
})
757+
commandIgnoredStringInputs.forEach((input) => {
758+
if (core.getInput(input)) {
759+
ignoredInputParameters.push(input)
760+
}
761+
})
762+
if (ignoredInputParameters.length > 0) {
763+
core.warning(
764+
`command parameter is used and the following other parameters are ignored: ${ignoredInputParameters.sort().join(', ')}.`
765+
)
766+
}
767+
}
722768

723769
/**
724770
* Run Cypress tests by collecting input parameters
725771
* and using Cypress module API to run tests.
772+
* If command parameter is specified, then run using @actions/exec instead.
726773
* @see https://on.cypress.io/module-api
727774
*/
728775
const runTests = async () => {
@@ -751,6 +798,7 @@ const runTests = async () => {
751798

752799
if (customCommand) {
753800
console.log('Using custom test command: %s', customCommand)
801+
validateCustomCommand() // catch ignored parameters and output warning
754802
return execCommand(customCommand, true, 'run tests')
755803
}
756804

0 commit comments

Comments
 (0)