Skip to content

Commit

Permalink
Merge pull request #10 from wings-software/team1-node
Browse files Browse the repository at this point in the history
node rules
  • Loading branch information
shaurya-harness authored Dec 18, 2023
2 parents eeaab1e + ba1293c commit 877e342
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
19 changes: 16 additions & 3 deletions builder/rules/harness/rule_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,31 @@ func ConfigureNode(fsys fs.FS, pipeline *spec.Pipeline) error {
return nil
}

// add well-known test
if _, ok := json.Scripts["test"]; ok {
// add test with junit for xml reports otherwise add well known test step
if _, ok := json.Scripts["test:junit"]; ok {
stage.Steps = append(stage.Steps, utils.CreateScriptStepWithReports(image,
"npm_test_reports",
"npm run test:junit",
))
} else if _, ok := json.Scripts["test"]; ok {
stage.Steps = append(stage.Steps, utils.CreateScriptStep(image,
"npm_test",
"npm run test",
))
}

// add well-known jest coverage command
if _, ok := json.Scripts["coverage"]; ok {
stage.Steps = append(stage.Steps, utils.CreateScriptStep(image,
"npm_coverage",
"npm run coverage",
))
}

// add well-known lint command
if _, ok := json.Scripts["lint"]; ok {
stage.Steps = append(stage.Steps, utils.CreateScriptStep(image,
"npm_test",
"npm_lint",
"npm run lint",
))
}
Expand Down
17 changes: 17 additions & 0 deletions utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,20 @@ func CreateScriptWithUserDefinitionAndReportPath(image, name, command string) *s

return step
}

// helper function to create a script step.
func CreateScriptStepWithReports(image, name, command string) *spec.Step {
script := new(spec.StepExec)
script.Run = command
script.Reports = []*spec.Report{{Type: "Junit", Path: spec.Stringorslice{"**/*.xml"}}}
if image != "" {
script.Image = image
}

step := new(spec.Step)
step.Name = name
step.Type = "script"
step.Spec = script

return step
}

0 comments on commit 877e342

Please sign in to comment.