@@ -6,22 +6,56 @@ let errorMessagesCount = 0;
66
77const ignoreErrors = [
88 "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" ,
916] ;
1017
1118// Register a global error listener
12- test . beforeEach ( async ( { page } ) => {
19+ test . beforeEach ( async ( { page, browserName } ) => {
1320 errorMessagesCount = 0 ;
1421
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" ) {
1731 return ;
1832 }
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 ) ;
2054 ++ errorMessagesCount ;
2155 } ) ;
2256} ) ;
2357
24- test . afterEach ( ( ) => {
58+ test . afterEach ( async ( ) => {
2559 expect ( errorMessagesCount ) . toBe ( 0 ) ;
2660} ) ;
2761
@@ -51,18 +85,40 @@ test("visits the app root url, sitemap.txt and robots.txt", async ({
5185 expect ( await page . locator ( "pre" ) . innerText ( ) ) . toMatchSnapshot ( "robots.txt" ) ;
5286} ) ;
5387
54- test ( "check menu items" , async ( { page } ) => {
88+ test ( "check menu items and each page " , async ( { page } ) => {
5589 await page . goto ( "/" ) ;
5690 const $menu = page . locator ( '[data-test-id="page-header-menu"]' ) ;
5791 const menuItems = $menu . getByRole ( "menuitem" ) ;
5892 const $$menuItems = await menuItems . all ( ) ;
5993 await page . waitForTimeout ( 500 ) ;
6094 await expect ( menuItems ) . toHaveCount ( 4 ) ;
6195
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+ }
66122} ) ;
67123
68124test ( "General flow" , async ( { page, context, browserName } ) => {
0 commit comments