1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-07-05 00:59:01 +02:00

npmExecuteScripts: allow passing a list of build descriptors to execute scripts for (#2312)

This change extends the npmExecuteScripts step to support execution of
npm scripts for specific modules. Previously, it was not possible to
execute npm scripts only for specific modules. Now, if the parameter
buildDesriptorList is set the scripts defined by the runScripts
parameter will be executed for the modules defined by
buildDescriptorList. Note, in this case the buildDescriptorExcludeList
will be ignored.
This commit is contained in:
Kevin Hudemann
2020-11-04 16:20:26 +01:00
committed by GitHub
parent e4979af112
commit a04e53df2a
7 changed files with 82 additions and 11 deletions

View File

@ -33,6 +33,7 @@ type npmConfig struct {
scriptOptions []string
virtualFrameBuffer bool
excludeList []string
packagesList []string
}
// npmExecutorMock mocking struct
@ -59,7 +60,7 @@ func (n *npmExecutorMock) FindPackageJSONFilesWithScript(packageJSONFiles []stri
}
// RunScriptsInAllPackages mock implementation
func (n *npmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOptions []string, scriptOptions []string, virtualFrameBuffer bool, excludeList []string) error {
func (n *npmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOptions []string, scriptOptions []string, virtualFrameBuffer bool, excludeList []string, packagesList []string) error {
if len(runScripts) != len(n.config.runScripts) {
return fmt.Errorf("RunScriptsInAllPackages was called with a different list of runScripts than config.runScripts")
}
@ -85,6 +86,10 @@ func (n *npmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOption
return fmt.Errorf("RunScriptsInAllPackages was called with a different value of excludeList than config.excludeList")
}
if len(packagesList) != len(n.config.packagesList) {
return fmt.Errorf("RunScriptsInAllPackages was called with a different value of packagesList than config.packagesList")
}
return nil
}
@ -112,6 +117,18 @@ func (n *npmExecutorMock) SetNpmRegistries() error {
}
func TestNpmExecuteScripts(t *testing.T) {
t.Run("Call with packagesList", func(t *testing.T) {
config := npmExecuteScriptsOptions{Install: true, RunScripts: []string{"ci-build", "ci-test"}, BuildDescriptorList: []string{"src/package.json"}}
utils := newNpmMockUtilsBundle()
utils.AddFile("package.json", []byte("{\"name\": \"Test\" }"))
utils.AddFile("src/package.json", []byte("{\"name\": \"Test\" }"))
npmExecutor := npmExecutorMock{utils: utils, config: npmConfig{install: config.Install, runScripts: config.RunScripts, packagesList: config.BuildDescriptorList}}
err := runNpmExecuteScripts(&npmExecutor, &config)
assert.NoError(t, err)
})
t.Run("Call with excludeList", func(t *testing.T) {
config := npmExecuteScriptsOptions{Install: true, RunScripts: []string{"ci-build", "ci-test"}, BuildDescriptorExcludeList: []string{"**/path/**"}}
utils := newNpmMockUtilsBundle()