@@ -6,22 +6,56 @@ let errorMessagesCount = 0;
6
6
7
7
const ignoreErrors = [
8
8
"ResizeObserver loop completed with undelivered notifications." ,
9
+ // Blocked by AdBlocker
10
+ "api-gateway.umami.dev" ,
11
+ ] ;
12
+ const ignoreConsoleErrors = [
13
+ // Blocked by AdBlocker
14
+ "api-gateway.umami.dev" ,
15
+ "Failed to load resource: net::ERR_FAILED" ,
9
16
] ;
10
17
11
18
// Register a global error listener
12
- test . beforeEach ( async ( { page } ) => {
19
+ test . beforeEach ( async ( { page, browserName } ) => {
13
20
errorMessagesCount = 0 ;
14
21
15
- page . on ( "pageerror" , ( error ) => {
16
- if ( ignoreErrors . includes ( error . message ) ) {
22
+ page . on ( "console" , ( consoleMessage ) => {
23
+ if ( consoleMessage . type ( ) !== "error" ) {
24
+ return ;
25
+ }
26
+
27
+ // Webkit again have strange behavior.
28
+ // It doesn't provide location for CSP error.
29
+ // And not reproducible in Safari browser.
30
+ if ( browserName === "webkit" ) {
17
31
return ;
18
32
}
19
- console . log ( ">> Console error: " , error ) ;
33
+
34
+ for ( const ignoreError of ignoreConsoleErrors ) {
35
+ if ( consoleMessage . text ( ) . includes ( ignoreError ) ) {
36
+ return ;
37
+ }
38
+ }
39
+ console . log (
40
+ ">> Console log (error): " ,
41
+ consoleMessage . text ( ) ,
42
+ consoleMessage . location ( ) ,
43
+ ) ;
44
+ ++ errorMessagesCount ;
45
+ } ) ;
46
+
47
+ page . on ( "pageerror" , ( error ) => {
48
+ for ( const ignoreError of ignoreErrors ) {
49
+ if ( error . message . includes ( ignoreError ) ) {
50
+ return ;
51
+ }
52
+ }
53
+ console . log ( ">> Console error: " , error , error . stack ) ;
20
54
++ errorMessagesCount ;
21
55
} ) ;
22
56
} ) ;
23
57
24
- test . afterEach ( ( ) => {
58
+ test . afterEach ( async ( ) => {
25
59
expect ( errorMessagesCount ) . toBe ( 0 ) ;
26
60
} ) ;
27
61
@@ -51,18 +85,40 @@ test("visits the app root url, sitemap.txt and robots.txt", async ({
51
85
expect ( await page . locator ( "pre" ) . innerText ( ) ) . toMatchSnapshot ( "robots.txt" ) ;
52
86
} ) ;
53
87
54
- test ( "check menu items" , async ( { page } ) => {
88
+ test ( "check menu items and each page " , async ( { page } ) => {
55
89
await page . goto ( "/" ) ;
56
90
const $menu = page . locator ( '[data-test-id="page-header-menu"]' ) ;
57
91
const menuItems = $menu . getByRole ( "menuitem" ) ;
58
92
const $$menuItems = await menuItems . all ( ) ;
59
93
await page . waitForTimeout ( 500 ) ;
60
94
await expect ( menuItems ) . toHaveCount ( 4 ) ;
61
95
62
- await expect ( $$menuItems [ 0 ] ) . toHaveText ( "Home" ) ;
63
- await expect ( $$menuItems [ 1 ] ) . toHaveText ( "Create Crypto Address" ) ;
64
- await expect ( $$menuItems [ 2 ] ) . toHaveText ( "Create Paper Wallet" ) ;
65
- await expect ( $$menuItems [ 3 ] ) . toHaveText ( "Paper Wallet Editor" ) ;
96
+ const pages = [
97
+ { index : 0 , url : "/" , title : "Home" } ,
98
+ { index : 1 , url : "/create-wallets/" , title : "Create Crypto Address" } ,
99
+ { index : 2 , url : "/paper-wallets/" , title : "Create Paper Wallet" } ,
100
+ { index : 3 , url : "/paper-wallet-editor/" , title : "Paper Wallet Editor" } ,
101
+ ] ;
102
+
103
+ for ( const { index, title } of pages ) {
104
+ await expect ( $$menuItems [ index ] ) . toHaveText ( title ) ;
105
+ }
106
+
107
+ // Check Content-Security-Policy.
108
+ // Need to refresh the page to check the CSP for each page separately.
109
+ if ( process . env . PLAYWRIGHT_USE_BUILD ) {
110
+ for ( const { index, url } of pages ) {
111
+ if ( index === 0 ) {
112
+ continue ;
113
+ }
114
+ const $item = $$menuItems [ index ] ;
115
+ await $item . click ( ) ;
116
+ await page . waitForURL ( url , { timeout : 5000 } ) ;
117
+ await page . waitForTimeout ( 500 ) ;
118
+ await page . reload ( ) ;
119
+ await page . waitForTimeout ( 1000 ) ;
120
+ }
121
+ }
66
122
} ) ;
67
123
68
124
test ( "General flow" , async ( { page, context, browserName } ) => {
0 commit comments