You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-07-07 01:06:40 +02:00
Add buildDescriptorExcludeList parameter to npmExecuteScripts step (#1800)
This change adds a buildDescriptorExcludeList parameter to npmExecuteScripts, to enable the exclusion of certain directories when executing npm scripts. Previously, npmExecuteScripts could only execute scripts in all packages. Now it is possible to provide paths or patterns as elements of the buildDescriptorExcludeList to exclude packages when executing npm scripts.
This commit is contained in:
@ -32,6 +32,7 @@ type npmConfig struct {
|
||||
runOptions []string
|
||||
scriptOptions []string
|
||||
virtualFrameBuffer bool
|
||||
excludeList []string
|
||||
}
|
||||
|
||||
// npmExecutorMock mocking struct
|
||||
@ -46,13 +47,19 @@ func (n *npmExecutorMock) FindPackageJSONFiles() []string {
|
||||
return packages
|
||||
}
|
||||
|
||||
// FindPackageJSONFiles mock implementation
|
||||
func (n *npmExecutorMock) FindPackageJSONFilesWithExcludes(excludeList []string) ([]string, error) {
|
||||
packages, _ := n.utils.Glob("**/package.json")
|
||||
return packages, nil
|
||||
}
|
||||
|
||||
// FindPackageJSONFilesWithScript mock implementation
|
||||
func (n *npmExecutorMock) FindPackageJSONFilesWithScript(packageJSONFiles []string, script string) ([]string, error) {
|
||||
return packageJSONFiles, nil
|
||||
}
|
||||
|
||||
// RunScriptsInAllPackages mock implementation
|
||||
func (n *npmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOptions []string, scriptOptions []string, virtualFrameBuffer bool) error {
|
||||
func (n *npmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOptions []string, scriptOptions []string, virtualFrameBuffer bool, excludeList []string) error {
|
||||
if len(runScripts) != len(n.config.runScripts) {
|
||||
return fmt.Errorf("RunScriptsInAllPackages was called with a different list of runScripts than config.runScripts")
|
||||
}
|
||||
@ -63,7 +70,7 @@ func (n *npmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOption
|
||||
}
|
||||
|
||||
if len(scriptOptions) != len(n.config.scriptOptions) {
|
||||
return fmt.Errorf("RunScriptsInAllPackages was called with a different list of runOptions than config.scriptOptions")
|
||||
return fmt.Errorf("RunScriptsInAllPackages was called with a different list of scriptOptions than config.scriptOptions")
|
||||
}
|
||||
|
||||
if len(runOptions) != len(n.config.runOptions) {
|
||||
@ -74,6 +81,10 @@ func (n *npmExecutorMock) RunScriptsInAllPackages(runScripts []string, runOption
|
||||
return fmt.Errorf("RunScriptsInAllPackages was called with a different value of virtualFrameBuffer than config.virtualFrameBuffer")
|
||||
}
|
||||
|
||||
if len(excludeList) != len(n.config.excludeList) {
|
||||
return fmt.Errorf("RunScriptsInAllPackages was called with a different value of excludeList than config.excludeList")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -101,6 +112,18 @@ func (n *npmExecutorMock) SetNpmRegistries() error {
|
||||
}
|
||||
|
||||
func TestNpmExecuteScripts(t *testing.T) {
|
||||
t.Run("Call with excludeList", func(t *testing.T) {
|
||||
config := npmExecuteScriptsOptions{Install: true, RunScripts: []string{"ci-build", "ci-test"}, BuildDescriptorExcludeList: []string{"**/path/**"}}
|
||||
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, excludeList: config.BuildDescriptorExcludeList}}
|
||||
err := runNpmExecuteScripts(&npmExecutor, &config)
|
||||
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Call with scriptOptions", func(t *testing.T) {
|
||||
config := npmExecuteScriptsOptions{Install: true, RunScripts: []string{"ci-build", "ci-test"}, ScriptOptions: []string{"--run"}}
|
||||
utils := newNpmMockUtilsBundle()
|
||||
|
Reference in New Issue
Block a user