How to use MergeAndCleanupJSONReports method of reporters Package

Best Ginkgo code snippet using reporters.MergeAndCleanupJSONReports

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

json_report.go

Source: json_report.go Github

copy
1package reporters
2
3import (
4	"encoding/json"
5	"fmt"
6	"os"
7
8	"github.com/onsi/ginkgo/v2/types"
9)
10
11//GenerateJSONReport produces a JSON-formatted report at the passed in destination
12func GenerateJSONReport(report types.Report, destination string) error {
13	f, err := os.Create(destination)
14	if err != nil {
15		return err
16	}
17	enc := json.NewEncoder(f)
18	enc.SetIndent("", "  ")
19	err = enc.Encode([]types.Report{
20		report,
21	})
22	if err != nil {
23		return err
24	}
25	return f.Close()
26}
27
28//MergeJSONReports produces a single JSON-formatted report at the passed in destination by merging the JSON-formatted reports provided in sources
29//It skips over reports that fail to decode but reports on them via the returned messages []string
30func MergeAndCleanupJSONReports(sources []string, destination string) ([]string, error) {
31	messages := []string{}
32	allReports := []types.Report{}
33	for _, source := range sources {
34		reports := []types.Report{}
35		data, err := os.ReadFile(source)
36		if err != nil {
37			messages = append(messages, fmt.Sprintf("Could not open %s:\n%s", source, err.Error()))
38			continue
39		}
40		err = json.Unmarshal(data, &reports)
41		if err != nil {
42			messages = append(messages, fmt.Sprintf("Could not decode %s:\n%s", source, err.Error()))
43			continue
44		}
45		os.Remove(source)
46		allReports = append(allReports, reports...)
47	}
48
49	f, err := os.Create(destination)
50	if err != nil {
51		return messages, err
52	}
53	enc := json.NewEncoder(f)
54	enc.SetIndent("", "  ")
55	err = enc.Encode(allReports)
56	if err != nil {
57		return messages, err
58	}
59	return messages, f.Close()
60}
61
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)