44 * SPDX-License-Identifier: Apache-2.0
55 */
66import assert from 'node:assert' ;
7- import { describe , it } from 'node:test' ;
7+ import { beforeEach , describe , it } from 'node:test' ;
88
99import type {
1010 Browser ,
@@ -13,6 +13,7 @@ import type {
1313 Page ,
1414 Target ,
1515 CDPSession ,
16+ Protocol ,
1617} from 'puppeteer-core' ;
1718import sinon from 'sinon' ;
1819
@@ -343,6 +344,21 @@ describe('NetworkCollector', () => {
343344} ) ;
344345
345346describe ( 'ConsoleCollector' , ( ) => {
347+ let issue : Protocol . Audits . InspectorIssue ;
348+
349+ beforeEach ( ( ) => {
350+ issue = {
351+ code : 'MixedContentIssue' ,
352+ details : {
353+ mixedContentIssueDetails : {
354+ insecureURL : 'test.url' ,
355+ resolutionStatus : 'MixedContentBlocked' ,
356+ mainResourceURL : '' ,
357+ } ,
358+ } ,
359+ } ;
360+ } ) ;
361+
346362 it ( 'emits issues on page' , async ( ) => {
347363 const browser = getMockBrowser ( ) ;
348364 const page = ( await browser . pages ( ) ) [ 0 ] ;
@@ -359,17 +375,6 @@ describe('ConsoleCollector', () => {
359375 } as ListenerMap ;
360376 } ) ;
361377 await collector . init ( ) ;
362-
363- const issue = {
364- code : 'MixedContentIssue' as const ,
365- details : {
366- mixedContentIssueDetails : {
367- insecureURL : 'test.url' ,
368- } ,
369- } ,
370- } ;
371-
372- // @ts -expect-error Types of protocol from Puppeteer and CDP are incopatible for Issues but it's the same type
373378 cdpSession . emit ( 'Audits.issueAdded' , { issue} ) ;
374379 sinon . assert . calledOnce ( onIssuesListener ) ;
375380
@@ -391,26 +396,18 @@ describe('ConsoleCollector', () => {
391396 } ) ;
392397 await collector . init ( ) ;
393398
394- const issue = {
395- code : 'MixedContentIssue' as const ,
396- details : {
397- mixedContentIssueDetails : {
398- insecureURL : 'test.url' ,
399- } ,
400- } ,
401- } ;
402399 const issue2 = {
403- code : 'PropertyRuleIssue ' as const ,
400+ code : 'ElementAccessibilityIssue ' as const ,
404401 details : {
405- propertyRuleIssueDetails : {
406- test : 'test' ,
402+ elementAccessibilityIssueDetails : {
403+ nodeId : 1 ,
404+ elementAccessibilityIssueReason : 'DisallowedSelectChild' ,
405+ hasDisallowedAttributes : true ,
407406 } ,
408407 } ,
409- } ;
408+ } satisfies Protocol . Audits . InspectorIssue ;
410409
411- // @ts -expect-error Types of protocol from Puppeteer and CDP are incopatible for Issues but it's the same type
412410 cdpSession . emit ( 'Audits.issueAdded' , { issue} ) ;
413- // @ts -expect-error Types of protocol from Puppeteer and CDP are incopatible for Issues but it's the same type
414411 cdpSession . emit ( 'Audits.issueAdded' , { issue : issue2 } ) ;
415412 const data = collector . getData ( page ) ;
416413 assert . equal ( data . length , 2 ) ;
@@ -430,20 +427,10 @@ describe('ConsoleCollector', () => {
430427 } ) ;
431428 await collector . init ( ) ;
432429
433- const issue = {
434- code : 'MixedContentIssue' as const ,
435- details : {
436- mixedContentIssueDetails : {
437- insecureURL : 'test.url' ,
438- } ,
439- } ,
440- } ;
441-
442- // @ts -expect-error Types of protocol from Puppeteer and CDP are incopatible for Issues but it's the same type
443430 cdpSession . emit ( 'Audits.issueAdded' , { issue} ) ;
444- // @ts -expect-error Types of protocol from Puppeteer and CDP are incopatible for Issues but it's the same type
445431 cdpSession . emit ( 'Audits.issueAdded' , { issue} ) ;
446- const collectedIssue = collector . getData ( page ) [ 0 ] as AggregatedIssue ;
432+ const collectedIssue = collector . getData ( page ) [ 0 ] ;
433+ assert ( collectedIssue instanceof AggregatedIssue ) ;
447434 assert . equal ( collectedIssue . code ( ) , 'MixedContentIssue' ) ;
448435 assert . equal ( collectedIssue . getAggregatedIssuesCount ( ) , 1 ) ;
449436 } ) ;
0 commit comments