How to use TrackDeprecation method of types Package

Best Ginkgo code snippet using types.TrackDeprecation

Run Ginkgo automation tests on LambdaTest cloud grid

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

deprecated_support_test.go

Source: deprecated_support_test.go Github

copy
1package types_test
2
3import (
4	"os"
5	"reflect"
6	"strings"
7
8	. "github.com/onsi/ginkgo/v2"
9	. "github.com/onsi/gomega"
10
11	"github.com/onsi/ginkgo/v2/formatter"
12	"github.com/onsi/ginkgo/v2/types"
13)
14
15var _ = Describe("Deprecation Support", func() {
16	Describe("Tracking Deprecations", func() {
17		var tracker *types.DeprecationTracker
18
19		BeforeEach(func() {
20			tracker = types.NewDeprecationTracker()
21			formatter.SingletonFormatter.ColorMode = formatter.ColorModePassthrough
22		})
23
24		AfterEach(func() {
25			formatter.SingletonFormatter.ColorMode = formatter.ColorModeTerminal
26		})
27
28		Context("with no tracked deprecations", func() {
29			It("reports no tracked deprecations", func() {
30				Ω(tracker.DidTrackDeprecations()).Should(BeFalse())
31			})
32		})
33
34		Context("with tracked dependencies", func() {
35			BeforeEach(func() {
36				tracker.TrackDeprecation(types.Deprecation{
37					Message: "Deprecation 1",
38					DocLink: "doclink-1",
39				}, types.CodeLocation{FileName: "foo.go", LineNumber: 17})
40				tracker.TrackDeprecation(types.Deprecation{
41					Message: "Deprecation 1",
42					DocLink: "doclink-1",
43				}, types.CodeLocation{FileName: "bar.go", LineNumber: 30})
44				tracker.TrackDeprecation(types.Deprecation{
45					Message: "Deprecation 2",
46					DocLink: "doclink-2",
47				})
48				tracker.TrackDeprecation(types.Deprecation{
49					Message: "Deprecation 3",
50				}, types.CodeLocation{FileName: "baz.go", LineNumber: 72})
51			})
52
53			It("reports tracked deprecations", func() {
54				Ω(tracker.DidTrackDeprecations()).Should(BeTrue())
55			})
56
57			It("generates a nicely formatted report", func() {
58				report := tracker.DeprecationsReport()
59				Ω(report).Should(HavePrefix("{{light-yellow}}You're using deprecated Ginkgo functionality:{{/}}\n{{light-yellow}}============================================={{/}}\n"))
60				Ω(report).Should(ContainSubstring(strings.Join([]string{
61					"  {{yellow}}Deprecation 1{{/}}",
62					"  {{bold}}Learn more at:{{/}} {{cyan}}{{underline}}https://onsi.github.io/ginkgo/MIGRATING_TO_V2#doclink-1{{/}}",
63					"    {{gray}}foo.go:17{{/}}",
64					"    {{gray}}bar.go:30{{/}}",
65					"",
66				}, "\n")))
67				Ω(report).Should(ContainSubstring(strings.Join([]string{
68					"  {{yellow}}Deprecation 2{{/}}",
69					"  {{bold}}Learn more at:{{/}} {{cyan}}{{underline}}https://onsi.github.io/ginkgo/MIGRATING_TO_V2#doclink-2{{/}}",
70					"",
71				}, "\n")))
72				Ω(report).Should(ContainSubstring(strings.Join([]string{
73					"  {{yellow}}Deprecation 3{{/}}",
74					"    {{gray}}baz.go:72{{/}}",
75				}, "\n")))
76			})
77
78			It("validates that all deprecations point to working documentation", func() {
79				v := reflect.ValueOf(types.Deprecations)
80				Ω(v.NumMethod()).Should(BeNumerically(">", 0))
81				for i := 0; i < v.NumMethod(); i += 1 {
82					m := v.Method(i)
83					deprecation := m.Call([]reflect.Value{})[0].Interface().(types.Deprecation)
84
85					if deprecation.DocLink != "" {
86						Ω(anchors.DocAnchors["MIGRATING_TO_V2.md"]).Should(ContainElement(deprecation.DocLink))
87					}
88				}
89			})
90		})
91
92		Context("when ACK_GINKGO_DEPRECATIONS is set", func() {
93			var origEnv string
94			BeforeEach(func() {
95				origEnv = os.Getenv("ACK_GINKGO_DEPRECATIONS")
96				os.Setenv("ACK_GINKGO_DEPRECATIONS", "v1.18.3-boop")
97			})
98
99			AfterEach(func() {
100				os.Setenv("ACK_GINKGO_DEPRECATIONS", origEnv)
101			})
102
103			It("does not track deprecations with lower version numbers", func() {
104				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation A", Version: "0.19.2"})
105				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation B", Version: "1.17.4"})
106				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation C", Version: "1.18.2"})
107				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation D", Version: "1.18.3"})
108				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation E", Version: "1.18.4"})
109				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation F", Version: "1.19.2"})
110				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation G", Version: "2.0.0"})
111				tracker.TrackDeprecation(types.Deprecation{Message: "Deprecation H"})
112
113				report := tracker.DeprecationsReport()
114				Ω(report).ShouldNot(ContainSubstring("Deprecation A"))
115				Ω(report).ShouldNot(ContainSubstring("Deprecation B"))
116				Ω(report).ShouldNot(ContainSubstring("Deprecation C"))
117				Ω(report).ShouldNot(ContainSubstring("Deprecation D"))
118				Ω(report).Should(ContainSubstring("Deprecation E"))
119				Ω(report).Should(ContainSubstring("Deprecation F"))
120				Ω(report).Should(ContainSubstring("Deprecation G"))
121				Ω(report).Should(ContainSubstring("Deprecation H"))
122
123				Ω(report).Should(ContainSubstring("ACK_GINKGO_DEPRECATIONS="))
124			})
125		})
126	})
127})
128
Full Screen

deprecated_dsl.go

Source: deprecated_dsl.go Github

copy
1package ginkgo
2
3import (
4	"time"
5
6	"github.com/onsi/ginkgo/v2/internal"
7	"github.com/onsi/ginkgo/v2/internal/global"
8	"github.com/onsi/ginkgo/v2/reporters"
9	"github.com/onsi/ginkgo/v2/types"
10)
11
12/*
13Deprecated: Done Channel for asynchronous testing
14
15The Done channel pattern is no longer supported in Ginkgo 2.0.
16See here for better patterns for asynchronouse testing: https://onsi.github.io/ginkgo/#patterns-for-asynchronous-testing
17
18For a migration guide see: https://onsi.github.io/ginkgo/MIGRATING_TO_V2#removed-async-testing
19*/
20type Done = internal.Done
21
22/*
23Deprecated: Custom Ginkgo test reporters are deprecated in Ginkgo 2.0.
24
25Use Ginkgo's reporting nodes instead and 2.0 reporting infrastructure instead. You can learn more here: https://onsi.github.io/ginkgo/#reporting-infrastructure
26For a migration guide see: https://onsi.github.io/ginkgo/MIGRATING_TO_V2#removed-custom-reporters
27*/
28type Reporter = reporters.DeprecatedReporter
29
30/*
31Deprecated: Custom Reporters have been removed in Ginkgo 2.0.  RunSpecsWithDefaultAndCustomReporters will simply call RunSpecs()
32
33Use Ginkgo's reporting nodes instead and 2.0 reporting infrastructure instead. You can learn more here: https://onsi.github.io/ginkgo/#reporting-infrastructure
34For a migration guide see: https://onsi.github.io/ginkgo/MIGRATING_TO_V2#removed-custom-reporters
35*/
36func RunSpecsWithDefaultAndCustomReporters(t GinkgoTestingT, description string, _ []Reporter) bool {
37	deprecationTracker.TrackDeprecation(types.Deprecations.CustomReporter())
38	return RunSpecs(t, description)
39}
40
41/*
42Deprecated: Custom Reporters have been removed in Ginkgo 2.0.  RunSpecsWithCustomReporters will simply call RunSpecs()
43
44Use Ginkgo's reporting nodes instead and 2.0 reporting infrastructure instead. You can learn more here: https://onsi.github.io/ginkgo/#reporting-infrastructure
45For a migration guide see: https://onsi.github.io/ginkgo/MIGRATING_TO_V2#removed-custom-reporters
46*/
47func RunSpecsWithCustomReporters(t GinkgoTestingT, description string, _ []Reporter) bool {
48	deprecationTracker.TrackDeprecation(types.Deprecations.CustomReporter())
49	return RunSpecs(t, description)
50}
51
52/*
53Deprecated: GinkgoTestDescription has been replaced with SpecReport.
54
55Use CurrentSpecReport() instead.
56You can learn more here: https://onsi.github.io/ginkgo/#getting-a-report-for-the-current-spec
57The SpecReport type is documented here: https://pkg.go.dev/github.com/onsi/ginkgo/v2/types#SpecReport
58*/
59type DeprecatedGinkgoTestDescription struct {
60	FullTestText   string
61	ComponentTexts []string
62	TestText       string
63
64	FileName   string
65	LineNumber int
66
67	Failed   bool
68	Duration time.Duration
69}
70type GinkgoTestDescription = DeprecatedGinkgoTestDescription
71
72/*
73Deprecated: CurrentGinkgoTestDescription has been replaced with CurrentSpecReport.
74
75Use CurrentSpecReport() instead.
76You can learn more here: https://onsi.github.io/ginkgo/#getting-a-report-for-the-current-spec
77The SpecReport type is documented here: https://pkg.go.dev/github.com/onsi/ginkgo/v2/types#SpecReport
78*/
79func CurrentGinkgoTestDescription() DeprecatedGinkgoTestDescription {
80	deprecationTracker.TrackDeprecation(
81		types.Deprecations.CurrentGinkgoTestDescription(),
82		types.NewCodeLocation(1),
83	)
84	report := global.Suite.CurrentSpecReport()
85	if report.State == types.SpecStateInvalid {
86		return GinkgoTestDescription{}
87	}
88	componentTexts := []string{}
89	componentTexts = append(componentTexts, report.ContainerHierarchyTexts...)
90	componentTexts = append(componentTexts, report.LeafNodeText)
91
92	return DeprecatedGinkgoTestDescription{
93		ComponentTexts: componentTexts,
94		FullTestText:   report.FullText(),
95		TestText:       report.LeafNodeText,
96		FileName:       report.LeafNodeLocation.FileName,
97		LineNumber:     report.LeafNodeLocation.LineNumber,
98		Failed:         report.State.Is(types.SpecStateFailureStates),
99		Duration:       report.RunTime,
100	}
101}
102
103/*
104Deprecated: GinkgoParallelNode() has been renamed to GinkgoParallelProcess()
105*/
106func GinkgoParallelNode() int {
107	deprecationTracker.TrackDeprecation(
108		types.Deprecations.ParallelNode(),
109		types.NewCodeLocation(1),
110	)
111	return GinkgoParallelProcess()
112}
113
114/*
115Deprecated: Benchmarker has been removed from Ginkgo 2.0
116
117Use Gomega's gmeasure package instead.
118You can learn more here: https://onsi.github.io/ginkgo/#benchmarking-code
119*/
120type Benchmarker interface {
121	Time(name string, body func(), info ...interface{}) (elapsedTime time.Duration)
122	RecordValue(name string, value float64, info ...interface{})
123	RecordValueWithPrecision(name string, value float64, units string, precision int, info ...interface{})
124}
125
126/*
127Deprecated: Measure() has been removed from Ginkgo 2.0
128
129Use Gomega's gmeasure package instead.
130You can learn more here: https://onsi.github.io/ginkgo/#benchmarking-code
131*/
132func Measure(_ ...interface{}) bool {
133	deprecationTracker.TrackDeprecation(types.Deprecations.Measure(), types.NewCodeLocation(1))
134	return true
135}
136
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

Most used method in

Trigger TrackDeprecation code on LambdaTest Cloud Grid

Execute automation tests with TrackDeprecation on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
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)