MCPcopy Index your code
hub / github.com/conventionalcommit/commitlint / TestJSONFormatter_WithIssues

Function TestJSONFormatter_WithIssues

test/formatter_test.go:84–118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestJSONFormatter_WithIssues(t *testing.T) {
85 linter := newDefaultLinter(t)
86 result, err := linter.ParseAndLint("invalid commit no type")
87 if err != nil {
88 t.Fatal(err)
89 }
90 f := &formatter.JSONFormatter{}
91 out, fErr := f.Format(result)
92 if fErr != nil {
93 t.Fatal(fErr)
94 }
95 var parsed map[string]interface{}
96 if jErr := json.Unmarshal([]byte(out), &parsed); jErr != nil {
97 t.Fatalf("invalid JSON output: %v", jErr)
98 }
99 issues, ok := parsed["issues"].([]interface{})
100 if !ok {
101 t.Fatal("expected 'issues' array in JSON")
102 }
103 if len(issues) == 0 {
104 t.Error("expected at least one issue for invalid commit")
105 }
106 // Verify each issue has mandatory fields
107 for i, raw := range issues {
108 entry, ok := raw.(map[string]interface{})
109 if !ok {
110 t.Fatalf("issue[%d] is not a map", i)
111 }
112 for _, field := range []string{"name", "severity", "description"} {
113 if _, exists := entry[field]; !exists {
114 t.Errorf("issue[%d] missing field %q", i, field)
115 }
116 }
117 }
118}
119
120func TestJSONFormatter_InputField(t *testing.T) {
121 linter := newDefaultLinter(t)

Callers

nothing calls this directly

Calls 4

FormatMethod · 0.95
newDefaultLinterFunction · 0.85
ParseAndLintMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected