1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-05 15:15:44 +02:00

Adapt npmExecuteEndToEndTests (#4008)

* Adapt step

* Adapt comment
This commit is contained in:
Linda Siebert 2022-09-16 17:30:19 +02:00 committed by GitHub
parent 25bfc61e95
commit 3ba7a8dfa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 131 additions and 78 deletions

View File

@ -70,17 +70,6 @@ class NpmExecuteEndToEndTestsTest extends BasePiperTest {
Utils.metaClass = null Utils.metaClass = null
} }
@Test
void noAppUrl() {
thrown.expect(hudson.AbortException)
thrown.expectMessage('[npmExecuteEndToEndTests] The execution failed, since no appUrls are defined. Please provide appUrls as a list of maps.')
stepRule.step.npmExecuteEndToEndTests(
script: nullScript,
stageName: "myStage"
)
}
@Test @Test
void appUrlsNoList() { void appUrlsNoList() {
def appUrl = "http://my-url.com" def appUrl = "http://my-url.com"
@ -153,6 +142,54 @@ class NpmExecuteEndToEndTestsTest extends BasePiperTest {
assert npmExecuteScriptsRule.hasParameter('scriptOptions', ["--launchUrl=${appUrl.url}"]) assert npmExecuteScriptsRule.hasParameter('scriptOptions', ["--launchUrl=${appUrl.url}"])
} }
@Test
void baseUrl() {
nullScript.commonPipelineEnvironment.configuration = [
stages: [
myStage: [
baseUrl: "http://my-url.com"
]
]
]
stepRule.step.npmExecuteEndToEndTests(
script: nullScript,
stageName: "myStage"
)
assertFalse(executedInParallel)
assert npmExecuteScriptsRule.hasParameter('script', nullScript)
assert npmExecuteScriptsRule.hasParameter('parameters', [dockerOptions: ['--shm-size 512MB']])
assert npmExecuteScriptsRule.hasParameter('virtualFrameBuffer', true)
assert npmExecuteScriptsRule.hasParameter('runScripts', ["ci-e2e"])
assert npmExecuteScriptsRule.hasParameter('scriptOptions', ["--baseUrl=http://my-url.com"])
}
@Test
void chooseScript() {
nullScript.commonPipelineEnvironment.configuration = [
stages: [
myStage: [
runScript: "wdio"
]
]
]
stepRule.step.npmExecuteEndToEndTests(
script: nullScript,
stageName: "myStage"
)
assertFalse(executedInParallel)
assert npmExecuteScriptsRule.hasParameter('script', nullScript)
assert npmExecuteScriptsRule.hasParameter('parameters', [dockerOptions: ['--shm-size 512MB']])
assert npmExecuteScriptsRule.hasParameter('virtualFrameBuffer', true)
assert npmExecuteScriptsRule.hasParameter('runScripts', ["wdio"])
assert npmExecuteScriptsRule.hasParameter('scriptOptions', [])
}
@Test @Test
void oneAppUrlWithCredentials() { void oneAppUrlWithCredentials() {
def appUrl = [url: "http://my-url.com", credentialId: 'testCred'] def appUrl = [url: "http://my-url.com", credentialId: 'testCred']

View File

@ -44,7 +44,15 @@ import static com.sap.piper.Prerequisites.checkScript
/** /**
* Docker image on which end to end tests should be executed * Docker image on which end to end tests should be executed
*/ */
'dockerImage' 'dockerImage',
/**
* Base URL of the application to be tested
*/
'baseUrl',
/**
* Credentials to access the application to be tested
*/
'credentialsId'
]) ])
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
@ -81,26 +89,20 @@ void call(Map parameters = [:]) {
def npmParameters = [:] def npmParameters = [:]
npmParameters.dockerOptions = ['--shm-size 512MB'] npmParameters.dockerOptions = ['--shm-size 512MB']
if (!config.appUrls) { if (config.appUrls && !(config.appUrls instanceof List)) {
error "[${STEP_NAME}] The execution failed, since no appUrls are defined. Please provide appUrls as a list of maps.\n"
}
if (!(config.appUrls instanceof List)) {
error "[${STEP_NAME}] The execution failed, since appUrls is not a list. Please provide appUrls as a list of maps. For example:\n" + error "[${STEP_NAME}] The execution failed, since appUrls is not a list. Please provide appUrls as a list of maps. For example:\n" +
"appUrls: \n" + " - url: 'https://my-url.com'\n" + " credentialId: myCreds" "appUrls: \n" + " - url: 'https://my-url.com'\n" + " credentialId: myCreds"
}
if (!config.runScript) {
error "[${STEP_NAME}] No runScript was defined."
} }
if (config.onlyRunInProductiveBranch && (config.productiveBranch != env.BRANCH_NAME)) { if (config.onlyRunInProductiveBranch && (config.productiveBranch != env.BRANCH_NAME)) {
return return
} }
for (int i = 0; i < config.appUrls.size(); i++) {
List credentials = [] List credentials = []
def appUrl = config.appUrls[i]
if (config.appUrls){
for (int i = 0; i < config.appUrls.size(); i++) {
def appUrl = config.appUrls[i]
if (!(appUrl instanceof Map)) { if (!(appUrl instanceof Map)) {
error "[${STEP_NAME}] The element ${appUrl} is not of type map. Please provide appUrls as a list of maps. For example:\n" + error "[${STEP_NAME}] The element ${appUrl} is not of type map. Please provide appUrls as a list of maps. For example:\n" +
"appUrls: \n" + " - url: 'https://my-url.com'\n" + " credentialId: myCreds" "appUrls: \n" + " - url: 'https://my-url.com'\n" + " credentialId: myCreds"
@ -111,12 +113,6 @@ void call(Map parameters = [:]) {
if (appUrl.credentialId) { if (appUrl.credentialId) {
credentials.add(usernamePassword(credentialsId: appUrl.credentialId, passwordVariable: 'e2e_password', usernameVariable: 'e2e_username')) credentials.add(usernamePassword(credentialsId: appUrl.credentialId, passwordVariable: 'e2e_password', usernameVariable: 'e2e_username'))
} }
Closure e2eTest = {
Utils utils = new Utils()
utils.unstashStageFiles(script, stageName)
try {
withCredentials(credentials) {
List scriptOptions = ["--launchUrl=${appUrl.url}"] List scriptOptions = ["--launchUrl=${appUrl.url}"]
if (appUrl.parameters) { if (appUrl.parameters) {
if (appUrl.parameters instanceof List) { if (appUrl.parameters instanceof List) {
@ -125,6 +121,29 @@ void call(Map parameters = [:]) {
error "[${STEP_NAME}] The parameters property is not of type list. Please provide parameters as a list of strings." error "[${STEP_NAME}] The parameters property is not of type list. Please provide parameters as a list of strings."
} }
} }
e2ETests = runTest(scriptOptions, credentials, e2ETests, index, script, config, npmParameters, stageName)
index++
}
}else{
if (config.credentialsId) {
credentials.add(usernamePassword(credentialsId: config.credentialsId, passwordVariable: 'e2e_password', usernameVariable: 'e2e_username'))
}
List scriptOptions = []
if (config.baseUrl){
scriptOptions = ["--baseUrl=${config.baseUrl}"]
}
e2ETests = runTest(scriptOptions, credentials, e2ETests, index, script, config, npmParameters, stageName)
}
runClosures(script, e2ETests, config.parallelExecution, "end to end tests")
}
}
def runTest(scriptOptions, credentials, e2ETests, index, script, config, npmParameters, stageName){
Closure e2eTest = {
Utils utils = new Utils()
utils.unstashStageFiles(script, stageName)
try {
withCredentials(credentials) {
npmExecuteScripts(script: script, parameters: npmParameters, virtualFrameBuffer: true, runScripts: [config.runScript], dockerImage: config.dockerImage, scriptOptions: scriptOptions, buildDescriptorExcludeList: config.buildDescriptorExcludeList) npmExecuteScripts(script: script, parameters: npmParameters, virtualFrameBuffer: true, runScripts: [config.runScript], dockerImage: config.dockerImage, scriptOptions: scriptOptions, buildDescriptorExcludeList: config.buildDescriptorExcludeList)
} }
@ -156,8 +175,5 @@ void call(Map parameters = [:]) {
} }
} }
} }
index++ return e2ETests
}
runClosures(script, e2ETests, config.parallelExecution, "end to end tests")
}
} }