Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 6791e5b

Browse files
ankur22inancgumus
andcommitted
Apply suggestions from code review
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
1 parent 7f17113 commit 6791e5b

File tree

1 file changed

+76
-57
lines changed

1 file changed

+76
-57
lines changed

tests/lifecycle_wait_test.go

Lines changed: 76 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,46 @@ import (
1616

1717
// General guidelines on lifecycle events:
1818
//
19-
// - load: This lifecycle event is emitted by the browser once:
20-
// 1. The HTML is loaded;
21-
// 2. The async scripts have loaded;
22-
// It does not wait for the other network requests to
23-
// complete.
19+
// load
2420
//
25-
// - domcontentloaded: This lifecycle event is emitted by the
26-
// browser once:
27-
// 1. The HTML is loaded;
28-
// It does not wait for the async scripts or
29-
// the other network requests to complete.
21+
// The load event is fired when the initial HTML document has been completely
22+
// loaded. It does not wait for the other network requests to complete.
3023
//
31-
// - networkidle: This lifecycle event is emitted by the browser once:
32-
// 1. The HTML is loaded;
33-
// 2. The async scripts have loaded;
34-
// 3. All other network requests have completed;
24+
// Emitted by the browser once:
25+
// 1. The HTML is loaded.
26+
// 2. The async scripts have loaded.
27+
//
28+
// domcontentloaded
29+
//
30+
// The DOMContentLoaded event is fired when the initial HTML document has been
31+
// completely loaded and parsed. It does not wait for the async scripts or the
32+
// other network requests to complete.
33+
//
34+
// Emitted by the browser once:
35+
// 1. The HTML is loaded.
36+
//
37+
// networkidle
38+
//
39+
// The networkidle event is fired when there are no network connections for at
40+
// least 500ms.
41+
//
42+
// Emitted by the browser once:
43+
// 1. The HTML is loaded.
44+
// 2. The async scripts have loaded.
45+
// 3. All other network requests have completed.
3546

3647
func TestLifecycleWaitForNavigation(t *testing.T) {
3748
// Test description
3849
//
39-
// 1. goto /home and wait for the specified lifecycle event.
40-
// 2. click on a link that navigates to a page, and wait on
50+
// Steps:
51+
// 1. goto /home and wait for the specified lifecycle event.
52+
// 2. click on a link that navigates to a page, and wait on
4153
// the specified lifecycle event.
4254
//
43-
// Success criteria: The click will perform a navigation away
44-
// from the current page, it should wait for
45-
// the specified lifecycle event and the result
46-
// of the page should match the original nav.
55+
// Success criteria:
56+
// The click will perform a navigation away from the current page,
57+
// it should wait for the specified lifecycle event and the result
58+
// of the page should match the original nav.
4759

4860
t.Parallel()
4961

@@ -143,13 +155,15 @@ func TestLifecycleWaitForNavigationTimeout(t *testing.T) {
143155

144156
// Test description
145157
//
146-
// 1. goto /home and wait for the networkidle lifecycle event.
147-
// 2. use WaitForNavigation with networkidle.
158+
// Steps:
159+
// 1. goto /home and wait for the networkidle lifecycle event.
160+
// 2. use WaitForNavigation with networkidle.
148161
//
149-
// Success criteria: Time out reached after navigation completed and
150-
// wait for lifecycle event set, to signify that
151-
// WaitForNavigation must be set before we navigate
152-
// to a new page.
162+
// Success criteria:
163+
// Time out reached after navigation completed and
164+
// wait for lifecycle event set, to signify that
165+
// WaitForNavigation must be set before we navigate
166+
// to a new page.
153167

154168
tb := newTestBrowser(t, withFileServer())
155169
p := tb.NewPage(nil)
@@ -177,14 +191,11 @@ func TestLifecycleWaitForNavigationTimeout(t *testing.T) {
177191
return tb.promise(waitForNav)
178192
},
179193
)
180-
prm.then(
181-
func() {
182-
resolved = true
183-
},
184-
func() {
185-
rejected = true
186-
},
187-
)
194+
prm.then(func() {
195+
resolved = true
196+
}, func() {
197+
rejected = true
198+
})
188199

189200
return nil
190201
})
@@ -199,11 +210,13 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
199210

200211
// Test description
201212
//
202-
// 1. goto /home and wait for the specified lifecycle event.
203-
// 2. use WaitForLoadState with the same specified lifecycle event.
213+
// Steps:
214+
// 1. goto /home and wait for the specified lifecycle event.
215+
// 2. use WaitForLoadState with the same specified lifecycle event.
204216
//
205-
// Success criteria: We want to ensure that the specified event is persisted in
206-
// memory, and we don't block on WaitForLoadState.
217+
// Success criteria:
218+
// We want to ensure that the specified event is persisted in
219+
// memory, and we don't block on WaitForLoadState.
207220

208221
tests := []struct {
209222
name string
@@ -253,12 +266,14 @@ func TestLifecycleWaitForLoadState(t *testing.T) {
253266
{
254267
// Test description
255268
//
256-
// 1. goto /home and wait for the domcontentloaded lifecycle event.
257-
// 2. use WaitForLoadState with networkidle.
269+
// Steps:
270+
// 1. goto /home and wait for the domcontentloaded lifecycle event.
271+
// 2. use WaitForLoadState with networkidle.
258272
//
259-
// Success criteria: We want to quickly move to calling WaitForLoadState
260-
// so that we wait until networkidle is received from
261-
// the browser -- not relying on the persisted state in memory.
273+
// Success criteria:
274+
// We want to quickly move to calling WaitForLoadState
275+
// so that we wait until networkidle is received from
276+
// the browser -- not relying on the persisted state in memory.
262277
name: "domcontentloaded then networkidle",
263278
pingSlowness: 100 * time.Millisecond,
264279
pingJSSlow: false,
@@ -315,11 +330,13 @@ func TestLifecycleReload(t *testing.T) {
315330

316331
// Test description
317332
//
318-
// 1. goto /home and wait for the specified lifecycle event.
319-
// 2. reload the page and wait for the specified lifecycle event.
333+
// Steps:
334+
// 1. goto /home and wait for the specified lifecycle event.
335+
// 2. reload the page and wait for the specified lifecycle event.
320336
//
321-
// Success criteria: The resulting page after reload is the same as
322-
// the initial navigation with goto.
337+
// Success criteria:
338+
// The resulting page after reload is the same as
339+
// the initial navigation with goto.
323340

324341
tests := []struct {
325342
name string
@@ -408,11 +425,13 @@ func TestLifecycleGotoWithSubFrame(t *testing.T) {
408425

409426
// Test description
410427
//
411-
// 1. goto /home (with iframe to /sub) and wait for the specified lifecycle event.
428+
// Steps:
429+
// 1. goto /home (with iframe to /sub) and wait for the specified lifecycle event.
412430
//
413-
// Success criteria: The web page (all frames) is in the expected state
414-
// once we receive the specified lifecycle event from
415-
// the browser.
431+
// Success criteria:
432+
// The web page (all frames) is in the expected state
433+
// once we receive the specified lifecycle event from
434+
// the browser.
416435

417436
tests := []struct {
418437
name string
@@ -490,10 +509,12 @@ func TestLifecycleGoto(t *testing.T) {
490509

491510
// Test description
492511
//
493-
// 1. goto /home and wait for the specified lifecycle event.
512+
// Steps:
513+
// 1. goto /home and wait for the specified lifecycle event.
494514
//
495-
// Success criteria: The web page is in the expected state once we receive
496-
// the specified lifecycle event from the browser.
515+
// Success criteria:
516+
// The web page is in the expected state once we receive
517+
// the specified lifecycle event from the browser.
497518

498519
tests := []struct {
499520
name string
@@ -712,9 +733,7 @@ func assertHome(
712733
},
713734
)
714735
if secondCheck != nil {
715-
prm.then(func() {
716-
secondCheck()
717-
})
736+
prm.then(secondCheck)
718737
}
719738

720739
return nil

0 commit comments

Comments
 (0)