@@ -964,6 +964,62 @@ it('should support HAR larger than 512MB', async ({ contextFactory, server, brow
964964 expect ( tail . toString ( ) ) . toMatch ( / \} \s * \} \s * $ / ) ;
965965} ) ;
966966
967+ it . only ( 'should record resource type' , async ( { contextFactory, server, asset } , testInfo ) => {
968+ server . setRoute ( '/resource-types.html' , ( req , res ) => {
969+ res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) ;
970+ res . end ( `
971+ <link rel="stylesheet" href="/resource-type-stylesheet.css">
972+ <script src="/resource-type-script.js"></script>
973+ <img src="/resource-type-image.png">
974+ ` ) ;
975+ } ) ;
976+ server . setRoute ( '/resource-type-stylesheet.css' , ( req , res ) => {
977+ res . writeHead ( 200 , { 'Content-Type' : 'text/css' } ) ;
978+ res . end ( `
979+ @font-face {
980+ font-family: 'iconfont';
981+ src: url('/resource-type-font.woff2') format('woff2');
982+ }
983+ body { font-family: 'iconfont'; }
984+ ` ) ;
985+ } ) ;
986+ server . setRoute ( '/resource-type-font.woff2' , ( req , res ) => {
987+ server . serveFile ( req , res , asset ( 'webfont/iconfont.woff2' ) ) ;
988+ } ) ;
989+ server . setRoute ( '/resource-type-script.js' , ( req , res ) => {
990+ res . writeHead ( 200 , { 'Content-Type' : 'application/javascript' } ) ;
991+ res . end ( 'window.__loaded = true;' ) ;
992+ } ) ;
993+ server . setRoute ( '/resource-type-image.png' , ( req , res ) => {
994+ server . serveFile ( req , res , asset ( 'pptr.png' ) ) ;
995+ } ) ;
996+
997+ const { page, getLog } = await pageWithHar ( contextFactory , testInfo ) ;
998+ await page . goto ( server . PREFIX + '/resource-types.html' ) ;
999+ await page . evaluate ( ( ) => fetch ( '/resource-type-fetch' ) . catch ( ( ) => { } ) ) ;
1000+ await page . evaluate ( ( ) => new Promise < void > ( resolve => {
1001+ const xhr = new XMLHttpRequest ( ) ;
1002+ xhr . open ( 'GET' , '/resource-type-xhr' ) ;
1003+ xhr . onloadend = ( ) => resolve ( ) ;
1004+ xhr . send ( ) ;
1005+ } ) ) ;
1006+ const log = await getLog ( ) ;
1007+
1008+ const typeForURL = log . entries . reduce ( ( accumulator , entry ) => {
1009+ accumulator [ entry . request . url ] = entry . _resourceType ;
1010+ return accumulator ;
1011+ } , { } ) ;
1012+ expect ( typeForURL ) . toMatchObject ( {
1013+ [ server . PREFIX + '/resource-types.html' ] : 'document' ,
1014+ [ server . PREFIX + '/resource-type-stylesheet.css' ] : 'stylesheet' ,
1015+ [ server . PREFIX + '/resource-type-script.js' ] : 'script' ,
1016+ [ server . PREFIX + '/resource-type-image.png' ] : 'image' ,
1017+ [ server . PREFIX + '/resource-type-font.woff2' ] : 'font' ,
1018+ [ server . PREFIX + '/resource-type-fetch' ] : 'fetch' ,
1019+ [ server . PREFIX + '/resource-type-xhr' ] : 'xhr' ,
1020+ } ) ;
1021+ } ) ;
1022+
9671023it . describe ( 'tracing.startHar' , ( ) => {
9681024 it ( 'should record a HAR with options' , async ( { contextFactory, server } , testInfo ) => {
9691025 const context = await contextFactory ( ) ;
0 commit comments