How to use emitBlock method of reporters Package

Best Ginkgo code snippet using reporters.emitBlock

default_reporter.go

Source:default_reporter.go Github

copy

Full Screen

...56 r.emit(r.f("- %d procs ", report.SuiteConfig.ParallelTotal))57 }58 } else {59 banner := r.f("Running Suite: %s - %s", report.SuiteDescription, report.SuitePath)60 r.emitBlock(banner)61 bannerWidth := len(banner)62 if len(report.SuiteLabels) > 0 {63 labels := strings.Join(report.SuiteLabels, ", ")64 r.emitBlock(r.f("{{coral}}[%s]{{/}} ", labels))65 if len(labels)+2 > bannerWidth {66 bannerWidth = len(labels) + 267 }68 }69 r.emitBlock(strings.Repeat("=", bannerWidth))70 out := r.f("Random Seed: {{bold}}%d{{/}}", report.SuiteConfig.RandomSeed)71 if report.SuiteConfig.RandomizeAllSpecs {72 out += r.f(" - will randomize all specs")73 }74 r.emitBlock(out)75 r.emit("\n")76 r.emitBlock(r.f("Will run {{bold}}%d{{/}} of {{bold}}%d{{/}} specs", report.PreRunStats.SpecsThatWillRun, report.PreRunStats.TotalSpecs))77 if report.SuiteConfig.ParallelTotal > 1 {78 r.emitBlock(r.f("Running in parallel across {{bold}}%d{{/}} processes", report.SuiteConfig.ParallelTotal))79 }80 }81}82func (r *DefaultReporter) WillRun(report types.SpecReport) {83 if r.conf.Verbosity().LT(types.VerbosityLevelVerbose) || report.State.Is(types.SpecStatePending|types.SpecStateSkipped) {84 return85 }86 r.emitDelimiter()87 indentation := uint(0)88 if report.LeafNodeType.Is(types.NodeTypesForSuiteLevelNodes) {89 r.emitBlock(r.f("{{bold}}[%s] %s{{/}}", report.LeafNodeType.String(), report.LeafNodeText))90 } else {91 if len(report.ContainerHierarchyTexts) > 0 {92 r.emitBlock(r.cycleJoin(report.ContainerHierarchyTexts, " "))93 indentation = 194 }95 line := r.fi(indentation, "{{bold}}%s{{/}}", report.LeafNodeText)96 labels := report.Labels()97 if len(labels) > 0 {98 line += r.f(" {{coral}}[%s]{{/}}", strings.Join(labels, ", "))99 }100 r.emitBlock(line)101 }102 r.emitBlock(r.fi(indentation, "{{gray}}%s{{/}}", report.LeafNodeLocation))103}104func (r *DefaultReporter) DidRun(report types.SpecReport) {105 v := r.conf.Verbosity()106 var header, highlightColor string107 includeRuntime, emitGinkgoWriterOutput, stream, denoter := true, true, false, r.specDenoter108 succinctLocationBlock := v.Is(types.VerbosityLevelSuccinct)109 hasGW := report.CapturedGinkgoWriterOutput != ""110 hasStd := report.CapturedStdOutErr != ""111 hasEmittableReports := report.ReportEntries.HasVisibility(types.ReportEntryVisibilityAlways) || (report.ReportEntries.HasVisibility(types.ReportEntryVisibilityFailureOrVerbose) && (!report.Failure.IsZero() || v.GTE(types.VerbosityLevelVerbose)))112 if report.LeafNodeType.Is(types.NodeTypesForSuiteLevelNodes) {113 denoter = fmt.Sprintf("[%s]", report.LeafNodeType)114 }115 switch report.State {116 case types.SpecStatePassed:117 highlightColor, succinctLocationBlock = "{{green}}", v.LT(types.VerbosityLevelVerbose)118 emitGinkgoWriterOutput = (r.conf.AlwaysEmitGinkgoWriter || v.GTE(types.VerbosityLevelVerbose)) && hasGW119 if report.LeafNodeType.Is(types.NodeTypesForSuiteLevelNodes) {120 if v.GTE(types.VerbosityLevelVerbose) || hasStd || hasEmittableReports {121 header = fmt.Sprintf("%s PASSED", denoter)122 } else {123 return124 }125 } else {126 header, stream = denoter, true127 if report.NumAttempts > 1 {128 header, stream = fmt.Sprintf("%s [FLAKEY TEST - TOOK %d ATTEMPTS TO PASS]", r.retryDenoter, report.NumAttempts), false129 }130 if report.RunTime > r.conf.SlowSpecThreshold {131 header, stream = fmt.Sprintf("%s [SLOW TEST]", header), false132 }133 }134 if hasStd || emitGinkgoWriterOutput || hasEmittableReports {135 stream = false136 }137 case types.SpecStatePending:138 highlightColor = "{{yellow}}"139 includeRuntime, emitGinkgoWriterOutput = false, false140 if v.Is(types.VerbosityLevelSuccinct) {141 header, stream = "P", true142 } else {143 header, succinctLocationBlock = "P [PENDING]", v.LT(types.VerbosityLevelVeryVerbose)144 }145 case types.SpecStateSkipped:146 highlightColor = "{{cyan}}"147 if report.Failure.Message != "" || v.Is(types.VerbosityLevelVeryVerbose) {148 header = "S [SKIPPED]"149 } else {150 header, stream = "S", true151 }152 case types.SpecStateFailed:153 highlightColor, header = "{{red}}", fmt.Sprintf("%s [FAILED]", denoter)154 case types.SpecStatePanicked:155 highlightColor, header = "{{magenta}}", fmt.Sprintf("%s! [PANICKED]", denoter)156 case types.SpecStateInterrupted:157 highlightColor, header = "{{orange}}", fmt.Sprintf("%s! [INTERRUPTED]", denoter)158 case types.SpecStateAborted:159 highlightColor, header = "{{coral}}", fmt.Sprintf("%s! [ABORTED]", denoter)160 }161 // Emit stream and return162 if stream {163 r.emit(r.f(highlightColor + header + "{{/}}"))164 return165 }166 // Emit header167 r.emitDelimiter()168 if includeRuntime {169 header = r.f("%s [%.3f seconds]", header, report.RunTime.Seconds())170 }171 r.emitBlock(r.f(highlightColor + header + "{{/}}"))172 // Emit Code Location Block173 r.emitBlock(r.codeLocationBlock(report, highlightColor, succinctLocationBlock, false))174 //Emit Stdout/Stderr Output175 if hasStd {176 r.emitBlock("\n")177 r.emitBlock(r.fi(1, "{{gray}}Begin Captured StdOut/StdErr Output >>{{/}}"))178 r.emitBlock(r.fi(2, "%s", report.CapturedStdOutErr))179 r.emitBlock(r.fi(1, "{{gray}}<< End Captured StdOut/StdErr Output{{/}}"))180 }181 //Emit Captured GinkgoWriter Output182 if emitGinkgoWriterOutput && hasGW {183 r.emitBlock("\n")184 r.emitBlock(r.fi(1, "{{gray}}Begin Captured GinkgoWriter Output >>{{/}}"))185 r.emitBlock(r.fi(2, "%s", report.CapturedGinkgoWriterOutput))186 r.emitBlock(r.fi(1, "{{gray}}<< End Captured GinkgoWriter Output{{/}}"))187 }188 if hasEmittableReports {189 r.emitBlock("\n")190 r.emitBlock(r.fi(1, "{{gray}}Begin Report Entries >>{{/}}"))191 reportEntries := report.ReportEntries.WithVisibility(types.ReportEntryVisibilityAlways)192 if !report.Failure.IsZero() || v.GTE(types.VerbosityLevelVerbose) {193 reportEntries = report.ReportEntries.WithVisibility(types.ReportEntryVisibilityAlways, types.ReportEntryVisibilityFailureOrVerbose)194 }195 for _, entry := range reportEntries {196 r.emitBlock(r.fi(2, "{{bold}}"+entry.Name+"{{gray}} - %s @ %s{{/}}", entry.Location, entry.Time.Format(types.GINKGO_TIME_FORMAT)))197 if representation := entry.StringRepresentation(); representation != "" {198 r.emitBlock(r.fi(3, representation))199 }200 }201 r.emitBlock(r.fi(1, "{{gray}}<< End Report Entries{{/}}"))202 }203 // Emit Failure Message204 if !report.Failure.IsZero() {205 r.emitBlock("\n")206 r.emitBlock(r.fi(1, highlightColor+"%s{{/}}", report.Failure.Message))207 r.emitBlock(r.fi(1, highlightColor+"In {{bold}}[%s]{{/}}"+highlightColor+" at: {{bold}}%s{{/}}\n", report.Failure.FailureNodeType, report.Failure.Location))208 if report.Failure.ForwardedPanic != "" {209 r.emitBlock("\n")210 r.emitBlock(r.fi(1, highlightColor+"%s{{/}}", report.Failure.ForwardedPanic))211 }212 if r.conf.FullTrace || report.Failure.ForwardedPanic != "" {213 r.emitBlock("\n")214 r.emitBlock(r.fi(1, highlightColor+"Full Stack Trace{{/}}"))215 r.emitBlock(r.fi(2, "%s", report.Failure.Location.FullStackTrace))216 }217 }218 r.emitDelimiter()219}220func (r *DefaultReporter) SuiteDidEnd(report types.Report) {221 failures := report.SpecReports.WithState(types.SpecStateFailureStates)222 if len(failures) > 1 {223 r.emitBlock("\n\n")224 r.emitBlock(r.f("{{red}}{{bold}}Summarizing %d Failures:{{/}}", len(failures)))225 for _, specReport := range failures {226 highlightColor, heading := "{{red}}", "[FAIL]"227 switch specReport.State {228 case types.SpecStatePanicked:229 highlightColor, heading = "{{magenta}}", "[PANICKED!]"230 case types.SpecStateAborted:231 highlightColor, heading = "{{coral}}", "[ABORTED]"232 case types.SpecStateInterrupted:233 highlightColor, heading = "{{orange}}", "[INTERRUPTED]"234 }235 locationBlock := r.codeLocationBlock(specReport, highlightColor, true, true)236 r.emitBlock(r.fi(1, highlightColor+"%s{{/}} %s", heading, locationBlock))237 }238 }239 //summarize the suite240 if r.conf.Verbosity().Is(types.VerbosityLevelSuccinct) && report.SuiteSucceeded {241 r.emit(r.f(" {{green}}SUCCESS!{{/}} %s ", report.RunTime))242 return243 }244 r.emitBlock("\n")245 color, status := "{{green}}{{bold}}", "SUCCESS!"246 if !report.SuiteSucceeded {247 color, status = "{{red}}{{bold}}", "FAIL!"248 }249 specs := report.SpecReports.WithLeafNodeType(types.NodeTypeIt) //exclude any suite setup nodes250 r.emitBlock(r.f(color+"Ran %d of %d Specs in %.3f seconds{{/}}",251 specs.CountWithState(types.SpecStatePassed)+specs.CountWithState(types.SpecStateFailureStates),252 report.PreRunStats.TotalSpecs,253 report.RunTime.Seconds()),254 )255 switch len(report.SpecialSuiteFailureReasons) {256 case 0:257 r.emit(r.f(color+"%s{{/}} -- ", status))258 case 1:259 r.emit(r.f(color+"%s - %s{{/}} -- ", status, report.SpecialSuiteFailureReasons[0]))260 default:261 r.emitBlock(r.f(color+"%s - %s{{/}}\n", status, strings.Join(report.SpecialSuiteFailureReasons, ", ")))262 }263 if len(specs) == 0 && report.SpecReports.WithLeafNodeType(types.NodeTypeBeforeSuite|types.NodeTypeSynchronizedBeforeSuite).CountWithState(types.SpecStateFailureStates) > 0 {264 r.emit(r.f("{{cyan}}{{bold}}A BeforeSuite node failed so all tests were skipped.{{/}}\n"))265 } else {266 r.emit(r.f("{{green}}{{bold}}%d Passed{{/}} | ", specs.CountWithState(types.SpecStatePassed)))267 r.emit(r.f("{{red}}{{bold}}%d Failed{{/}} | ", specs.CountWithState(types.SpecStateFailureStates)))268 if specs.CountOfFlakedSpecs() > 0 {269 r.emit(r.f("{{light-yellow}}{{bold}}%d Flaked{{/}} | ", specs.CountOfFlakedSpecs()))270 }271 r.emit(r.f("{{yellow}}{{bold}}%d Pending{{/}} | ", specs.CountWithState(types.SpecStatePending)))272 r.emit(r.f("{{cyan}}{{bold}}%d Skipped{{/}}\n", specs.CountWithState(types.SpecStateSkipped)))273 }274}275/* Emitting to the writer */276func (r *DefaultReporter) emit(s string) {277 if len(s) > 0 {278 r.lastChar = s[len(s)-1:]279 r.lastEmissionWasDelimiter = false280 r.writer.Write([]byte(s))281 }282}283func (r *DefaultReporter) emitBlock(s string) {284 if len(s) > 0 {285 if r.lastChar != "\n" {286 r.emit("\n")287 }288 r.emit(s)289 if r.lastChar != "\n" {290 r.emit("\n")291 }292 }293}294func (r *DefaultReporter) emitDelimiter() {295 if r.lastEmissionWasDelimiter {296 return297 }298 r.emitBlock(r.f("{{gray}}%s{{/}}", strings.Repeat("-", 30)))299 r.lastEmissionWasDelimiter = true300}301/* Rendering text */302func (r *DefaultReporter) f(format string, args ...interface{}) string {303 return r.formatter.F(format, args...)304}305func (r *DefaultReporter) fi(indentation uint, format string, args ...interface{}) string {306 return r.formatter.Fi(indentation, format, args...)307}308func (r *DefaultReporter) cycleJoin(elements []string, joiner string) string {309 return r.formatter.CycleJoin(elements, joiner, []string{"{{/}}", "{{gray}}"})310}311func (r *DefaultReporter) codeLocationBlock(report types.SpecReport, highlightColor string, succinct bool, usePreciseFailureLocation bool) string {312 texts, locations, labels := []string{}, []types.CodeLocation{}, [][]string{}...

Full Screen

Full Screen

emitBlock

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 dest := draw2dimg.NewImage(400, 400)4 gc := draw2dimg.NewGraphicContext(dest)5 gc.SetFillColor(color.White)6 gc.SetStrokeColor(color.Black)7 gc.SetLineWidth(2)8 gc.MoveTo(0, 0)9 gc.LineTo(400, 0)10 gc.LineTo(400, 400)11 gc.LineTo(0, 400)12 gc.Close()13 gc.FillStroke()14 gc.BeginPath()15 gc.MoveTo(200, 200)16 gc.ArcTo(200, 200, 100, 100, 0, 2*3.14)17 gc.Close()18 gc.FillStroke()19 gc.BeginPath()20 gc.MoveTo(100, 100)21 gc.LineTo(300, 100)22 gc.LineTo(300, 300)23 gc.LineTo(100, 300)24 gc.Close()25 gc.FillStroke()26 gc.BeginPath()27 gc.MoveTo(50, 50)28 gc.LineTo(350, 50)29 gc.LineTo(350, 350)30 gc.LineTo(50, 350)31 gc.Close()32 gc.FillStroke()33 gc.BeginPath()34 gc.MoveTo(200, 50)35 gc.LineTo(350, 350)36 gc.LineTo(50, 350)37 gc.Close()38 gc.FillStroke()39 gc.BeginPath()40 gc.MoveTo(200, 50)41 gc.LineTo(250, 200)42 gc.LineTo(400, 200)43 gc.LineTo(275, 300)44 gc.LineTo(325, 450)45 gc.LineTo(200, 350)46 gc.LineTo(75, 450

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful